camelcase speed methods

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
      var properties = ["-webkit-animation-iteration-count", "-webkit-animation-name", "-webkit-animation-play-state", "-webkit-animation-timing-function", "-webkit-appearance", "-webkit-backface-visibility", "-webkit-background-clip", "-webkit-background-composite", "-webkit-box-flex", "-webkit-box-flex-group", "-webkit-box-lines", "-webkit-box-ordinal-group", "-webkit-box-orient", "-webkit-box-pack", "-webkit-box-reflect", "-webkit-box-shadow", "-webkit-color-correction", "-webkit-column-break-after", "-webkit-column-break-before", "-webkit-column-break-inside", "-webkit-column-count", "-webkit-column-gap", "-webkit-column-rule-color", "-webkit-column-rule-style", "-webkit-column-rule-width", "-webkit-column-span", "-webkit-column-width", "-webkit-dashboard-region", "-webkit-font-smoothing", "-webkit-highlight", "-webkit-line-break", "-webkit-line-clamp", "-webkit-margin-before-collapse"];
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
by RegExp (MooTools)
var i = properties.length;

while (i--) {

    properties[i].replace(/-\D/g, function(match) {
        return match.charAt(1).toUpperCase();
    });

}
pending…
by Array.split
var k = properties.length;
var j, i, s, camelcased;

while (k--) {

      camelcased = '';
      s = properties[k];
      s = s.split('-');
      i = 0, j = s.length;
     
      while ( ++i < j ) {
        camelcased += s[i].charAt(0).toUpperCase() + s[i].slice(1);
      }

}
pending…
by String.indexOf
var index,
    lastIndex,
    camelcased,
    k = properties.length;

while (k--) {

    camelcased = properties[k];
    index = 0; lastIndex = 0;

    while ( (index = camelcased.indexOf('-')) !== -1) {
        camelcased = camelcased.slice(0, index) + camelcased.charAt(index + 1).toUpperCase() + camelcased.slice(index + 2);    
        lastIndex = index;
    }

}
pending…

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

Compare results of other browsers

0 comments

Add a comment