String Reversal

JavaScript performance comparison

Test case created by Paul Sayre

Info

Comparison of different string reversal methods

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var str = 'Bacon ipsum dolor sit amet pork belly venison fatback rump beef, speck shankle tenderloin beef ribs cow sirloin biltong kielbasa. Ground round speck filet mignon pancetta ball tip jowl. Chuck pastrami short ribs, filet mignon sirloin turkey shank pork belly cow drumstick. Capicola shankle meatball, ball tip bresaola short ribs meatloaf shank hamburger venison t-bone kielbasa sausage biltong tri-tip. Salami meatball beef fatback pork chop, venison ham prosciutto kielbasa. Brisket kielbasa drumstick strip steak short ribs tenderloin short loin. Venison rump tail, meatball jerky shankle hamburger drumstick sausage pancetta corned beef flank pork belly brisket pork loin.';
};
</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
split, reverse, join
var rev = str.split('').reverse().join('');
pending…
Iterate backwards
var i = str.length,
  rev = '';

while(i--) {
  rev += str.charAt(i);
}
pending…
Iterate backwards, array
var i = str.length,
  rev = [];

while(i--) {
  rev.push(str.charAt(i));
}
rev = rev.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. Here’s a list of current revisions for this page:

0 comments

Add a comment