Created
November 13, 2010 03:47
-
-
Save marioaquino/675063 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var counter1 = 0, counter2 = 0; | |
var i,j,l,ll; | |
var single = new Array(1000000); | |
var double = new Array(1000); | |
for(i = 0, l = double.length; i < l; i = (i + 1)) { | |
double[i] = new Array(1000); | |
} | |
var start = new Date(); | |
for(i = 0, l = single.length; i < l; i = (i + 1)) { | |
single[i] = 'foo'; | |
counter1 = counter1 + 1; | |
} | |
var end1 = new Date() - start; | |
//-------------------------------------------------------- | |
var start2 = new Date(); | |
for(i = 0,l = double.length; i < l; i = (i + 1)) { | |
for(j = 0, ll = double[i].length; j < ll; j = (j + 1)) { | |
double[i][j] = 'foo'; | |
counter2 = counter2 + 1; | |
} | |
} | |
var end2 = new Date() - start2; | |
print('First: ' + end1 + ' Second: ' + end2); | |
print('Counter1: ' + counter1 + ' Counter2: ' + counter2); | |
/** | |
mario:~$ v8 test.js | |
First: 136 Second: 31 | |
Counter1: 1000000 Counter2: 1000000 | |
mario:~$ v8 test.js | |
First: 135 Second: 31 | |
Counter1: 1000000 Counter2: 1000000 | |
mario:~$ v8 test.js | |
First: 136 Second: 30 | |
Counter1: 1000000 Counter2: 1000000 | |
mario:~$ v8 test.js | |
First: 135 Second: 31 | |
Counter1: 1000000 Counter2: 1000000 | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment