set-vs-obj-comparison

Benchmark created by whiteand on


Setup

var chars = "123qweabcd"
  var string = "123ewqqwe123qweacbdqweabcdw123qewa"

Test runner

Ready to run.

Testing in
TestOps/sec
With object
const chrSymbolsDict = {}
let index = chars.length
while (index--) {
  chrSymbolsDict[chars[index]] = true
}
index = string.length
while (index-- && chrSymbolsDict[string[index]] === true) {}
ready
With set
const chrSymbolsSet = new Set()
let index = chars.length
while (index--) {
  chrSymbolsSet.add(chars[index])
}
index = string.length
while (index-- && chrSymbolsSet.has(string[index])) {}
ready

Revisions

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