Data access (v2)

Revision 2 of this benchmark created on


Setup

const obj = {
	a: 1,
	b: 2,
	c: 3,
	d: 4,
	e: 5,
}

const map = new Map();
map.set("a", 1);
map.set("b", 2);
map.set("c", 3);
map.set("d", 4);
map.set("e", 5);


const frozen = Object.freeze({
	a: 1,
	b: 2,
	c: 3,
	d: 4,
	e: 5,
})

const arr = [1, 2, 3, 4, 5]

const typed = new Uint8Array(arr)

Test runner

Ready to run.

Testing in
TestOps/sec
Object access
const fn = (x) => obj[x];

fn('a');
fn('b');
fn('c');
fn('d');
fn('e');
ready
Array access
const fn = (i) => arr[i];

fn(0);
fn(1);
fn(2);
fn(3);
fn(4);
ready
Typed array access
const fn = (i) => typed[i];

fn(0);
fn(1);
fn(2);
fn(3);
fn(4);
ready
Frozen object access
const fn = (x) => frozen[x];

fn('a');
fn('b');
fn('c');
fn('d');
fn('e');
ready
Map access
const fn = (x) => map.get(x);

fn('a');
fn('b');
fn('c');
fn('d');
fn('e');
ready

Revisions

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