random-string-2

JavaScript performance comparison

Test case created by monolithed

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.

Testing in unknown unknown
Test Ops/sec
random_1
random_1(1000);
pending…
random_2
random_2(1000);
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