javascript - Object.keys execution-time -
i did benchmarking on setup (i7 @ 3.07ghz, 6gb ram) object.keys method , noticed interesting results.
this code tried:
var foo = {}; (var = 0; < 600000; i++) { foo[i] = true; } console.time("foobar"); var keys = object.keys(foo); console.timeend("foobar");
i replaced xxx different values, starting @ 10 000 , going 1 000 000. when came 400k execution-time around 121ms, 500k ~130ms. @ 600k jumped 250ms. why this?
you can examine how memory object foo uses.
when i = 600000 => foo object occupies around 2.4 mb
when i = 500000 => foo object occupies around 2mb
so, cpu cache size around 2mb, , when need more memory can handle, performance degrades non-linearly (as linear memory consumption less 2 mb)
Comments
Post a Comment