Skip to content
angerangel edited this page Mar 19, 2013 · 1 revision

USAGE

   SPEED? /no-io /times

DESCRIPTION

Returns approximate speed benchmarks [eval cpu memory file-io].

SPEED? is a function value.

REFINEMENTS

  • /no-io -- Skip the I/O test
  • /times -- Show time for each test

#SOURCE

speed?: make function! [  [
    {Returns approximate speed benchmarks [eval cpu memory file-io].}
    /no-io "Skip the I/O test"
    /times "Show time for each test"
    /local result x calc tmp file secs
][
    result: copy []
    foreach block [
        [
            loop 100000 [
                x: 1 * index? back next "x"
                x: 1 * index? back next "x"
                x: 1 * index? back next "x"
                x: 1 * index? back next "x"
            ]
            calc: [100000 / secs / 100]
        ] [
            tmp: make binary! 500000
            insert/dup tmp "abcdefghij" 50000
            loop 10 [
                random tmp
                decompress compress tmp
            ]
            calc: [(length? tmp) * 10 / secs / 1900]
        ] [
            repeat n 40 [
                change/dup tmp to-char n 500000
            ]
            calc: [(length? tmp) * 40 / secs / 1024 / 1024]
        ] [
            unless no-io [
                write file: %tmp-junk.txt ""
                tmp: make string! 32000 * 5
                insert/dup tmp "test^/" 32000
                loop 100 [
                    write file tmp
                    read file
                ]
                delete file
                calc: [(length? tmp) * 100 * 2 / secs / 1024 / 1024]
            ]
        ]
    ] [
        secs: now/precise
        calc: 0
        recycle
        do block
        secs: to decimal! difference now/precise secs
        append result to integer! do calc
        if times [append result secs]
    ]
    result
] ]

Clone this wiki locally