I submitted this benchmark to rebol.org, but it must have gotten
lost in the mail.

On my machine, this runs at 6.8 seconds per iteration.

REBOL [
    Title:   "Count Change Benchmark"
    Date:    11-11-1999
    File:    %change.r
    Author:  "John C."
    Email:   [EMAIL PROTECTED]
    Purpose: {
        Simple benchmark ported to REBOL.  Counts the number of ways
        to make change for a given amount.  To use, run the function
        BENCH.  It will print out the number of ways to make change
        for $2.00, (should be 2435), and the amount of time needed for
        one iterations of the program.

        See http://www.webcom.com/nazgul/change.html for the same
        benchmarks in other languages.
    }
    Category:  'general
]

first-denomination: func [kinds-of-coins] [
    switch kinds-of-coins [
        1 [1]
        2 [5]
        3 [10]
        4 [25]
        5 [50]
        6 [100]]]

cc: func [amount kinds-of-coins] [
    either amount = 0
        [1]
        [either (amount < 0) or (kinds-of-coins = 0)
            [0]
            [(cc amount - first-denomination kinds-of-coins
                 kinds-of-coins) +
             (cc amount kinds-of-coins - 1)]]]

bench: func [] [
    start: fourth now
    result: loop 10 [cc 200 5]
    end: fourth now
    print [result (end - start) / 10]
]




______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Reply via email to