Array reorder perf

JavaScript performance comparison

Test case created by TriStarGod

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const max = 1000;
  const source = [];
  for(let i = 0; i < max; ++i) {
    source.push(`id${i}`);
  }
  const queryResults = [];
  for(let i = max; i > -1; --i) {
    queryResults.push({ id:`id${i}`, res: i });
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Obj 2 array
const temp = {};
for(let i = 0; i < queryResults.length; ++i) {
  const r = queryResults[i];
  temp[r.id] = r;
}
const found1 = [];
for(let i = 0; i < source.length; ++i) {
  found1.push(temp[source[i]]);
}
pending…
array find
const found2 = [];
for(let i = 0; i < source.length; ++i) {
  found2.push(queryResults.find(({ id }) => id === source[i]));
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 Comments