Last active
December 21, 2015 07:29
-
-
Save tusharmath/6271339 to your computer and use it in GitHub Desktop.
Working performance comparison between typed arrays and simple array
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
operatorInt = (count, items) -> | |
i=0 | |
start = (new Date).getTime() | |
while(i++ != count) | |
items[0] = 1000 | |
return (new Date).getTime() - start | |
operatorSimple = (count, items) -> | |
i=0 | |
start = (new Date).getTime() | |
while(i++ != count) | |
items[0] = 1000 | |
return (new Date).getTime() - start | |
times = 1000 #* 1000 | |
simple = 0 | |
typed = 0 | |
while(times-- != 0) | |
size = 1000*1000 | |
arrSize = size | |
simpleArray = new Array arrSize | |
uArray = new Uint8Array arrSize | |
intArray = new Int8Array arrSize | |
simple += operatorSimple(size, simpleArray) | |
typed += operatorInt(size, intArray) | |
console.log(times) if(times%100 is 0) | |
console.log('Simple:', simple) | |
console.log('Typed:', typed) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment