set-vs-obj-comparison

JavaScript performance comparison

Test case created by whiteand

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var chars = "123qweabcd"
  var string = "123ewqqwe123qweacbdqweabcdw123qewa"

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
With object
const chrSymbolsDict = {}
let index = chars.length
while (index--) {
  chrSymbolsDict[chars[index]] = true
}
index = string.length
while (index-- && chrSymbolsDict[string[index]] === true) {}
pending…
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])) {}
pending…

Revisions

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

0 Comments