Skip to content

Instantly share code, notes, and snippets.

@greggirwin
Last active October 28, 2017 22:23
Show Gist options
  • Save greggirwin/dd172d5dd1e3445b16052a89f000637f to your computer and use it in GitHub Desktop.
Save greggirwin/dd172d5dd1e3445b16052a89f000637f to your computer and use it in GitHub Desktop.
compare-times perf test idea for Red
; Stats added by @toomasv
compare-times: func [
blocks "Block of code blocks to performance compare"
/count ct
/local t n baseline res blk stats1 memory time code template
][
ct: any [ct 1]
t: now/time/precise
loop ct [do []]
baseline: now/time/precise - t
res: collect [
foreach blk blocks [
t: now/time/precise
stats1: stats
loop ct [do blk]
n: now/time/precise - t - baseline
keep reduce [round/to n .001 stats - stats1 copy blk]
]
]
;new-line/skip sort/skip res 3 on 3
sort/skip res 3
insert res ["Time" "Memory" Code]
template: [pad (time) 12 #"|" pad (memory) 11 #"|" (mold code)]
foreach [time memory code] res [
print compose template
]
]
;>> compare-times/count [[flatten-levels copy b] [flatten-change copy b]] 100
;Time | Memory | Code
;0:00:00.246 | 4202496 | [flatten-change copy b]
;0:00:00.368 | 2183168 | [flatten-levels copy b]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment