static vs. dynamic property access

Benchmark created on


Setup

let object = { a: 42, b: "foo", c: true, d: ["bar"] };

Test runner

Ready to run.

Testing in
TestOps/sec
static key
let key = ["a", "b", "c", "d"][Math.floor(Math.random() * 3)]; // unused, to balance tests
let value = object.a
ready
dynamic-static key
let key = ["a", "b", "c", "d"][Math.floor(Math.random() * 3)]; // unused, to balance tests
let value = object["a"]
ready
dynamic (but fixed) key
let key = "a";
let key_ = ["a", "b", "c", "d"][Math.floor(Math.random() * 3)]; // unused, to balance tests
let value = object[key];
ready
dynamic (and changing) key
let key = ["a", "b", "c", "d"][Math.floor(Math.random() * 3)];
let value = object[key];
ready
dynamic with callback (fixed)
let key_ = ["a", "b", "c", "d"][Math.floor(Math.random() * 3)]; // unused, to balance tests
let getKey = () => "a";
let value = object[getKey()];
ready
dynamic with callback (changing)
let getKey = () => ["a", "b", "c", "d"][Math.floor(Math.random() * 3)];
let value = object[getKey()];
ready

Revisions

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