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.

  1. when i = 600000 => foo object occupies around 2.4 mb

  2. 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

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -