Rebol 编程/速度?
外观
< Rebol 编程
SPEED? /no-io /times
返回近似速度基准 [eval cpu memory file-io]。
SPEED? 是一个函数值。
- /no-io -- 跳过 I/O 测试
- /times -- 显示每个测试的时间
speed?: func [
{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: head insert/dup "" "test^/" 32000
loop 100 [
write/binary file tmp
read/binary 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
]