Javascript String reversal

JavaScript performance comparison

Test case created by Jackie Xu

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var test1 = 'abc',
        test2 = 'qwertyuiopasdfghjklzxcvbnm',
        test3 = 'qwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzqwertyuiopoiutrewqasdfghklkjgfdsazxcvbnmmbvcxzv';
};
</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 and Join 1
test1.split('').reverse().join();
pending…
Split and Join 2
test2.split('').reverse().join();
pending…
Split and Join 3
test3.split('').reverse().join();
pending…
Array, Unshift and Join 1
var tempArray = [],
    length = test1.length;

for (var i = 0; i < length; i++) {
    tempArray.unshift(test1.charAt(i));
}

tempArray.join('');
pending…
Array, Unshift and Join 2
var tempArray = [],
    length = test2.length;

for (var i = 0; i < length; i++) {
    tempArray.unshift(test2.charAt(i));
}

tempArray.join('');
pending…
Array, Unshift and Join 3
var tempArray = [],
    length = test3.length;

for (var i = 0; i < length; i++) {
    tempArray.unshift(test3.charAt(i));
}

tempArray.join('');
pending…
String Manipulation 1
var reversedStr = '',
    length = test1.length;

for (var i = 0; i < length; i++) {
    reversedStr = test1.charAt(i) + reversedStr;
}
pending…
String Manipulation 2
var reversedStr = '',
    length = test2.length;

for (var i = 0; i < length; i++) {
    reversedStr = test2.charAt(i) + reversedStr;
}
pending…
String Manipulation 3
var reversedStr = '',
    length = test3.length;

for (var i = 0; i < length; i++) {
    reversedStr = test3.charAt(i) + reversedStr;
}
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