number to string (v13)

Revision 13 of this benchmark created by 4esn0k on


Preparation HTML

<script>
  var num = (1024 * 1024 * 1024 * 1024);
  var str = "";

var array = [0,0,0,0,0,0,0,0,
             0,0,0,0,0,0,0,0,
             0,0,0,0,0,0,0,0,
             0,0,0,0,0,0,0,0];

var toString = function (n, radix) {
  var k = -1;
  while (n > 0) {
    var q = Math.floor(n / radix);
    var r = n - radix * q;
    array[++k] = r < 10 ? r + 48 : r - 10 + 97;
    n = q;
  }
  return String.fromCharCode(array);
};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
String literal
str = Math.floor(Math.random() * 1000000).toString(10);
ready
custom
str = toString(Math.floor(Math.random() * 1000000), 10);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.