Skip to content

Instantly share code, notes, and snippets.

@rebolek
Created July 18, 2012 11:22
Show Gist options
  • Save rebolek/3135678 to your computer and use it in GitHub Desktop.
Save rebolek/3135678 to your computer and use it in GitHub Desktop.
Check speed of math operations
Red/System[]
#include %C-library.reds
sine-osc: func [
x [float!] ; 0..1
return: [float!] ; -1..1
/local
y [float!]
][
x: x - 0.5
either x < 0.0 [y: 0.0 - x][y: x]
0.0 - ((8.0 * x) + (-16.0 * x * y))
]
square-osc: func [
x [float!] ; 0..1
return: [float!] ; -1..1
][
either x < 0.5 [-1.0][1.0]
]
; ---
f: 0.0
n: process-time
while [f <= 1.0][
sine-osc f
f: f + 0.00000001
]
print ["sine-osc time: " process-time - n lf]
f: 0.0
n: process-time
while [f <= 1.0][
square-osc f
f: f + 0.00000001
]
print ["square-osc time: " process-time - n lf]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment