Created
July 18, 2012 11:22
-
-
Save rebolek/3135678 to your computer and use it in GitHub Desktop.
Check speed of math operations
This file contains 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/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