reverse speeds

JavaScript performance comparison

Revision 2 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var s = 'I am a string that will be reversed. 12345.';

};
</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
split join reverse
function reverse_split_join(s) {
  return s.split('').reverse().join('');
}
pending…
For Negative Concat
function reverse_for_neg_concat(s) {
  var reverse = '';
  for(i = s.length-1; i >= 0; i--) {
    reverse += s[i];
  }
  return reverse;
}
pending…
For Negative join
function reverse_for_neg_join(s) {
  var reverse = [];
  for(i = s.length-1; i >= 0; i--) {
    reverse.push(s[i]);
  }
  return reverse.join('');
}
pending…
For Positive Concat
function reverse_for_pos_concat(s) {
  var reverse = '', _ref = s.length - 1;
  for(i = 0; i <= _ref; i++) {
    reverse += value[_ref - i];
  }
  return reverse;
}
pending…
For Positive Join
function reverse_for_pos_join(s) {
  var reverse = [], _ref = s.length - 1;
  for(i = 0; i <= _ref; i++) {
    reverse.push(value[_ref - i]);
  }
  return reverse;
}
pending…
While Negative Concat
function reverse_while_neg_concat(s) {
  var reverse = '', _ref = s.length-1;
  i = _ref;
  while(i >= 0) {
    reverse += s[i];
    i--;
  }
  return reverse;
}
pending…
While Negative Join
function reverse_while_neg_join(s) {
  var reverse = [], _ref = s.length-1;
  i = _ref;
  while(i >= 0) {
    reverse.push(s[i]);
    i--;
  }
  return reverse.join('');
}
pending…
While Positive Concat
function reverse_while_pos_concat(s) {
  var reverse = [], i = 0;
  while(i <= s.length-1) {
    reverse += s[i];
    i++;
  }
  return reverse;
}
pending…
While Positive Join

function reverse_while_pos_join(s) {
  var reverse = [], i = 0;
  while(i <= s.length-1) {
    reverse.push(s[i]);
    i++;
  }
  return reverse.join('');
}
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