camelize opt

JavaScript performance comparison

Revision 2 of this test case created by a

Preparation code

var STRING_CAMELIZE_REGEXP = (/(\-|_|\.|\s)+(.)?/g);
var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

function camelize1(str) {
  return str.replace(STRING_CAMELIZE_REGEXP, (match, separator, chr) =>
    chr ? chr.toUpperCase() : ''
  ).replace(/^([A-Z])/, match =>
    match.toLowerCase()
  );
}

function camelize2(str) {
  return str.replace(STRING_CAMELIZE_REGEXP, (match, separator, chr) =>
    chr ? chr.toUpperCase() : ''
  ).replace(/^([A-Z])/, match =>
    match.toLowerCase()
  );
}
      
<script>
Benchmark.prototype.setup = function() {
  a

};

Benchmark.prototype.teardown = function() {
  a

};
</script>

Preparation code output

var STRING_CAMELIZE_REGEXP = (/(\-|_|\.|\s)+(.)?/g); var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; function camelize1(str) { return str.replace(STRING_CAMELIZE_REGEXP, (match, separator, chr) => chr ? chr.toUpperCase() : '' ).replace(/^([A-Z])/, match => match.toLowerCase() ); } function camelize2(str) { return str.replace(STRING_CAMELIZE_REGEXP, (match, separator, chr) => chr ? chr.toUpperCase() : '' ).replace(/^([A-Z])/, match => match.toLowerCase() ); }

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

Revisions

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

0 Comments

var STRING_CAMELIZE_REGEXP = (/(\-|_|\.|\s)+(.)?/g); var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; function camelize1(str) { return str.replace(STRING_CAMELIZE_REGEXP, (match, separator, chr) => chr ? chr.toUpperCase() : '' ).replace(/^([A-Z])/, match => match.toLowerCase() ); } function camelize2(str) { return str.replace(STRING_CAMELIZE_REGEXP, (match, separator, chr) => chr ? chr.toUpperCase() : '' ).replace(/^([A-Z])/, match => match.toLowerCase() ); }