CSS class name matching

JavaScript performance comparison

Test case created by kripod

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var selectorText = '.lorem.ipsum.dolor';
  var slicedSelectorText = selectorText.slice(1);

};
</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
RegExp with a capture group
var className = /^.([^.]+)/.exec(selectorText)[1];
pending…
RegExp without a capture group, slice-after
var className = /^.[^.]+/.exec(selectorText)[0].slice(1);
pending…
RegExp without a capture group, slice-before v1
var className = /^[^.]+/.exec(slicedSelectorText)[0];
pending…
Array splitting v1
var className = selectorText.split('.')[1];
pending…
RegExp without a capture group, slice-before v2
var className = /^[^.]*/.exec(slicedSelectorText)[0];
pending…
RegExp without a capture group, slice-before v3
var className = /^.[^.]*/.exec(slicedSelectorText)[0];
pending…
String slicing v2
var index = slicedSelectorText.indexOf('.', 1);
var className = slicedSelectorText.slice(index > 0 ? index : 9);
pending…
Array splitting v2
var className = slicedSelectorText.split('.')[0];
pending…
String slicing v1 with pseudoclass support
var index = selectorText.indexOf('.', 2);
if (index < 0) {
  index = selectorText.indexOf(':', 2);
  if (index < 0) index = 9;
}
var className = selectorText.slice(1, index);
pending…
Search & Slice with pseudoclass support
var className = selectorText.slice(1, selectorText.search(/.[.:]/) + 1);
pending…

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

0 Comments