Access to cache

Benchmark created on


Setup

const N = 10_000;
const TEST_N = 1000;

const getStrHash = (i) => `fjklsdjflk${i}jfkladfd`; 

const intIds = Array(N).fill(null).map((_, i) => i);
const strIds = intIds.map(getStrHash);

const getRandomElem = (arr) => arr[Math.floor(Math.random()*arr.length)];

const intToValArr = intIds.reduce((arr, e) => {
	arr[e] = e + '124124124';
	return arr;
}, []);
const intToValMap = Object.fromEntries(intIds.map(e => [e, e + '124124124']));
const strToValMap = Object.fromEntries(strIds.map(e => [e, e + '124124124']));


Test runner

Ready to run.

Testing in
TestOps/sec
1
let i = TEST_N;
let res = '';
while(i--) {
	const key = getRandomElem(intIds);
    res += intToValArr[key];
}
ready
2
let i = TEST_N;
let res = '';
while(i--) {
	const key = getRandomElem(intIds);
    res += intToValMap[key];
}
ready
3
let i = TEST_N;
let res = '';
while(i--) {
	const key = getRandomElem(strIds);
    res += strToValMap[key];
}
ready
4
let i = TEST_N;
let res = '';
while(i--) {
	const keyInt = getRandomElem(intIds);
	const key = getStrHash(keyInt);
    res += strToValMap[key];
}
ready

Revisions

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