Normalize Array

JavaScript performance comparison

Test case created by koorchik

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const users = [
    { id: 1, name: "someName" },
    { id: 2, name: "someName" },
    { id: 3, name: "someName" },
    { id: 4, name: "someName" },
    { id: 5, name: "someName" },
    { id: 6, name: "someName" },
    { id: 7, name: "someName" },
    { id: 8, name: "someName" },
    { id: 9, name: "someName" },
    { id: 10, name: "someName" },
    { id: 11, name: "someName" },
    { id: 12, name: "someName" },
    { id: 13, name: "someName" },
    { id: 14, name: "someName" },
    { id: 15, name: "someName" },
    { id: 16, name: "someName" },
    { id: 17, name: "someName" },
    { id: 18, name: "someName" },
    { id: 19, name: "someName" },
    { id: 20, name: "someName" },
    { id: 21, name: "someName" },
    { id: 22, name: "someName" },
    { id: 23, name: "someName" },
    { id: 24, name: "someName" },
    { id: 25, name: "someName" },
    { id: 26, name: "someName" },
    { id: 27, name: "someName" },
    { id: 28, name: "someName" },
    { id: 29, name: "someName" },
    { id: 30, name: "someName" },
    { id: 31, name: "someName" }
  ];

};
</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
reduce
const usersById = users.reduce((acc, user) => ({
  ...acc, [user.id]: user
}), {} );
pending…
for of
const usersById = {};

for (const user of users) {
  usersById[user.id] = user;
}
pending…

Compare results of other browsers

Revisions

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

0 Comments