Created
March 31, 2010 07:07
-
-
Save fjenett/350033 to your computer and use it in GitHub Desktop.
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
// benchmark to see if right-shift is faster than floor( / ). | |
// this is to quickly find which grid-element a location belongs to. | |
// test is in 1D only. | |
void draw () | |
{ | |
//setup | |
int grid = 3; | |
float gridP = pow(2,grid); // 16 >> 4 == 16 / 2^4 | |
float rnd = random(1000); | |
int fInt=0, fInt2=0; | |
// using right-shifting | |
long ts = System.currentTimeMillis(); | |
for (int i=0; i< 20000; i++) | |
fInt = ((int)rnd) >> grid; | |
float ts1 = (System.currentTimeMillis()-ts)/1000.0; | |
// using floor | |
ts = System.currentTimeMillis(); | |
for (int i=0; i< 20000; i++) | |
fInt2 = floor(rnd / gridP); | |
float ts2 = (System.currentTimeMillis()-ts)/1000.0; | |
// results | |
println( rnd + " shift: " + fInt + " " + ts1 ); | |
println( rnd + " floor: " + fInt2 + " " + ts2 ); | |
println( "" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment