Last active
August 23, 2016 09:44
-
-
Save jbilcke/f928f79381324b1d0f377f202e288719 to your computer and use it in GitHub Desktop.
Array<Array>, Array<{}> or Array<Object>? tests made with node 6.3.0 on a mac
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
// Execution time: 1048 | |
// { rss: 1028186112, heapTotal: 1015271424, heapUsed: 969132048 } | |
var start = new Date().getTime(); | |
var arr = []; | |
for (i = 0; i < 10000000; ++i) { | |
arr.push([Math.random(), Math.random()]) | |
} | |
var end = new Date().getTime(); | |
var time = end - start; | |
console.log('Execution time: ' + time); | |
console.log(process.memoryUsage()) |
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
// this example performs the worse in term of speed! | |
// probably because of the manual allocation of x and y | |
//Execution time: 3109 | |
// { rss: 740888576, heapTotal: 722391040, heapUsed: 693790992 } | |
var start = new Date().getTime(); | |
class Obj { | |
constructor(x,y){ | |
this.x = x; | |
this.y = y; | |
} | |
} | |
var arr = []; | |
for (i = 0; i < 10000000; ++i) { | |
arr.push(new Obj(Math.random(), Math.random())) | |
} | |
var end = new Date().getTime(); | |
var time = end - start; | |
console.log('Execution time: ' + time); | |
console.log(process.memoryUsage()) |
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
// objects have overhead, but I suspect that v8 optimizes | |
// when it sees that the size of the object, ie. number of stored references (keys) never change | |
// Execution time: 987 | |
// { rss: 788381696, heapTotal: 771977216, heapUsed: 729104864 } | |
var start = new Date().getTime(); | |
var arr = []; | |
for (i = 0; i < 10000000; ++i) { | |
arr.push({x: Math.random(), y: Math.random()}) | |
} | |
var end = new Date().getTime(); | |
var time = end - start; | |
console.log('Execution time: ' + time); | |
console.log(process.memoryUsage()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment