string building
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var str = '';
var array;
// generate a random 20 character string
(function () {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",
rnum;
for (var i = 0; i < 20; i++) {
rnum = Math.floor(Math.random() * 61);
str += chars.substring(rnum, rnum + 1);
}
array = str.split('');
}());
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
concatenate |
|
pending… |
push |
|
pending… |
concatenate 2 |
|
pending… |
concatenate 2 re-evaluate length |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments