random-string-2
JavaScript performance comparison
Preparation code
<script>
</script>
<script>
Benchmark.prototype.setup = function() {
var random_1 = function(size) {
var result = '';
while (size--) {
result += (0 | Math.random() * 32).toString(32);
}
return result;
};
var random_2 = function(length) {
if (!length || length < 0) return "";
return (new Array(++length)).join(0).replace(/./g,function() {
return(0 | Math.random() * 32).toString(32)
});
};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
random_1 |
|
pending… |
random_2 |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments