hyphenate

JavaScript performance comparison

Test case created by Fabio Costa

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var _uppercasePattern = /([A-Z])/g;
  var str = 'ufihasdoiduhsfuhSdsaiudhsuhSfiudhuhJifdhnsiufGfhdnsuhifafOifuydhifuhsJfgsdfgg';

};
</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
regexp2
str.replace(_uppercasePattern, function(all, letter) {
  return '-' + letter.toLowerCase();
});
pending…
string manipulation
var arr = str.split('');
for (var i = 0, len = str.length; i < len; i++) {
  var letter = arr[i];
  if (letter >= 'A' && letter <= 'Z') {
    arr[i] = letter.toLowerCase();
    arr.splice(i, 0, '-');
  }
}
arr.join('');
pending…
regexp1
str.replace(_uppercasePattern, '-$1').toLowerCase();
pending…

Compare results of other browsers

Revisions

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

0 Comments