map lookup test speed

Benchmark created on


Description

Tis

Setup

const strings = [];
const numbers = [];

const stringMap = {};
const sparseArray = []
for (let i = 0; i < 1000; i += 1) {
	strings.push(i + (' string number').repeat(40))
	numbers.push(i);
	
	
	stringMap[strings[i]] = i;
	sparseArray[i] = i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
lookup string
var result = [];
for (let string of strings) {
	result.push(stringMap[string]);
}

return result;
ready
lookup arr
var result = [];
for (let number of numbers) {
	result.push(numbers[number]);
}

return result;
ready

Revisions

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