Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Object Hashmap vs Array.indexOf
Matching a string against more than one possibility.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Browser:
Chrome 149
Operating system:
Linux
Device Platform:
Desktop
Date tested:
5 days ago
Test name
Executions per second
Object Hash-map
5088156.5 Ops/sec
Array.indexOf
2329851.0 Ops/sec
Script Preparation code:
var testArray = ['a','b', 'c','d','e','f','g','h','i','j', 'k', 'l','m','n' ,'bar','o', 'p', 'q', 'r', 's','t','u', 'v','w','x','y', 'z']; let i =0; var objectHash = testArray.reduce((acc, key) => {acc[key] = i++; return acc;},{});
Tests:
Object Hash-map
const testStrFirst = 'foo'; objectHash[testStrFirst]; const testStrSecond = 'bar'; objectHash[testStrSecond]; const testStrNotMatch = 'baz'; objectHash[testStrNotMatch];
Array.indexOf
const testStrFirst = 'foo'; testArray.indexOf(testStrFirst); const testStrSecond = 'bar'; testArray.indexOf(testStrSecond); const testStrNotMatch = 'baz'; testArray.indexOf(testStrNotMatch);