Skip to content

Instantly share code, notes, and snippets.

@mrinalwadhwa
Created November 22, 2010 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrinalwadhwa/709580 to your computer and use it in GitHub Desktop.
Save mrinalwadhwa/709580 to your computer and use it in GitHub Desktop.
protected function while_loop1():void {
var l:int = 500000000,
i:int = 0;
while (i < l){
i++;
}
}
protected function while_loop2():void {
var l:int = 500000000,
i:int = 0,
n:int = l;
while (n--){
i++;
}
}
protected function while_loop_duffs_device1():void {
var l:int = 500000000,
i:int = 0,
n:int = l % 8;
while (n--) {
i++;
}
n = Math.floor(l/8);
while (n--) {
i++;
i++;
i++;
i++;
i++;
i++;
i++;
i++
}
}
protected function while_loop_duffs_device2():void {
var l:int = 500000000,
i:int = 0,
n:int = l % 8;
while (n--) {
i++;
}
n = Math.floor(l * 0.125); // multiply may be faster than devide
while (n--) {
i++;
i++;
i++;
i++;
i++;
i++;
i++;
i++
}
}
protected function while_loop_duffs_device3():void {
var l:int = 500000000,
i:int = 0,
n:int = l % 8;
while (n--) {
i++;
}
n = (l/8) ^ 0; // bitwise operator instead of Math.floor()
while (n--) {
i++;
i++;
i++;
i++;
i++;
i++;
i++;
i++
}
}
protected function while_loop_duffs_device4():void {
var l:int = 500000000,
i:int = 0,
n:int = l % 8;
while (n--) {
i++;
}
n = (l * 0.125) ^ 0; // bitwise and multiply
while (n--) {
i++;
i++;
i++;
i++;
i++;
i++;
i++;
i++
}
}
Running tests on MAC 10,1,103,19 RELEASE with loopsMultiple=1...
[TestSuite name='DuffsDevicePerfTest' tareTime=0 time=-1]
[MethodTest name='while_loop1' time=1259.5 min=1159 max=1351 deviation=0.152 memory=0]
[MethodTest name='while_loop2' time=985.0 min=843 max=1108 deviation=0.269 memory=0]
[MethodTest name='while_loop_duffs_device1' time=113.5 min=89 max=138 deviation=0.432 memory=0]
[MethodTest name='while_loop_duffs_device2' time=114.0 min=89 max=138 deviation=0.430 memory=0]
[MethodTest name='while_loop_duffs_device3' time=122.0 min=105 max=139 deviation=0.279 memory=0]
[MethodTest name='while_loop_duffs_device4' time=124.2 min=108 max=141 deviation=0.266 memory=0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment