Created
October 1, 2017 16:38
-
-
Save dockimbel/3e7f72d244c8a9d405eb91d2a010346e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Note: "https://gitter.im/red/red?at=59d0e788f7299e8f539496d3" | |
] | |
time-it: func [block /count ct /local t baseline][ | |
ct: any [ct 1] | |
t: now/time/precise | |
loop ct [do []] | |
baseline: now/time/precise - t | |
t: now/time/precise | |
loop ct [do block] | |
now/time/precise - t - baseline | |
] | |
v1: make vector! 10000 | |
v2: make vector! 10000 | |
repeat c 10000 [v1/:c: v2/:c: c - 1] | |
do-count: function [][ | |
sum: 0 | |
repeat i 10000 [sum: sum + v1/:i + v2/:i] | |
sum | |
] | |
do-count2: routine [ | |
v1 [vector!] v2 [vector!] return: [integer!] | |
/local sum i p1 p2 | |
][ | |
sum: 0 | |
i: 1 | |
p1: as int-ptr! vector/rs-head v1 | |
p2: as int-ptr! vector/rs-head v2 | |
loop 10000 [ | |
sum: p1/i + p2/i + sum | |
i: i + 1 | |
] | |
sum | |
] | |
sum: 0 | |
time: time-it/count [sum: do-count] 1000 | |
print [ "Calculation of" sum "took" time ] | |
sum: 0 | |
time: time-it/count [sum: do-count2 v1 v2] 1000 | |
print [ "Calculation of" sum "took" time ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment