number to string (v16)

Revision 16 of this benchmark created by 4esn0k on


Preparation HTML

<script>
var digits = "0123456789abcdefghijklmnopqrstuvwxyz";

var toString = function (n, radix) {
  var s = "";
  do {
    var x = Math.floor(n / radix);
    s += digits.charAt(n - radix * x);
    n = x;
  } while (n !== 0);
  return s;
};

var v0 = 42;
var v1 = 4503599627370495;

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Number.prototype.toString, radix = 10
var s = Math.floor(v0 + Math.random() * 1000000).toString(10);
ready
custom, radix = 10
var s = toString(Math.floor(v0 + Math.random() * 1000000), 10);
ready
Number.prototype.toString, radix = 16
var s = Math.floor(v0 + Math.random() * 1000000).toString(16);
ready
custom, radix = 16
var s = toString(Math.floor(v0 + Math.random() * 1000000), 16);
 
ready
+Number.prototype.toString, radix = 10
var s = Math.floor(v1 + Math.random() * 1000000).toString(10);
ready
+custom, radix = 10
var s = toString(Math.floor(v1 + Math.random() * 1000000), 10);
ready
+Number.prototype.toString, radix = 16
var s = Math.floor(v1 + Math.random() * 1000000).toString(16);
ready
+custom, radix = 16
var s = toString(Math.floor(v1 + Math.random() * 1000000), 16);
 
ready

Revisions

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