ask then index vs just take vs getItem

Benchmark created on


Setup

const key = 'scott';
const notKey = 'not-scott';
localStorage.setItem(key, 'great');

Teardown

localStorage.clear();

Test runner

Ready to run.

Testing in
TestOps/sec
Ask then take
if (key in localStorage) {
	const value = localStorage[key];
	console.log('key', value);
}

if (notKey in localStorage) {
	const value = localStorage[notKey];
	console.log('notKey', value);
}

ready
Just take

{
	const value = localStorage[key];
	console.log('key', value);
}
{
	const value = localStorage[notKey];
	console.log('notKey', value);
}
ready

Revisions

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