Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Created October 1, 2017 16:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dockimbel/3e7f72d244c8a9d405eb91d2a010346e to your computer and use it in GitHub Desktop.
Save dockimbel/3e7f72d244c8a9d405eb91d2a010346e to your computer and use it in GitHub Desktop.
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