Cast To String (v16)

Revision 16 of this benchmark created by adon on


Test runner

Ready to run.

Testing in
TestOps/sec
String Function
var u, n = null,
  i = 87,
  s = 'tacos',
  b = true,
  u2, n2, i2, s2, b2;
u2 = String(u);
n2 = String(n);
i2 = String(i);
s2 = String(s);
b2 = String(b);
ready
String Constructor
var u, n = null,
  i = 87,
  s = 'tacos',
  b = true,
  u2, n2, i2, s2, b2;
u2 = new String(u);
n2 = new String(n);
i2 = new String(i);
s2 = new String(s);
b2 = new String(b);
ready
Prepend Empty String
var u, n = null,
  i = 87,
  s = 'tacos',
  b = true,
  u2, n2, i2, s2, b2;
u2 = '' + u;
n2 = '' + n;
i2 = '' + i;
s2 = '' + s;
b2 = '' + b;
ready
Append Empty String
var u, n = null,
  i = 87,
  s = 'tacos',
  b = true,
  u2, n2, i2, s2, b2;
u2 = u + '';
n2 = n + '';
i2 = i + '';
s2 = s + '';
b2 = b + '';
ready
Conditional toString
var u, n = null,
  i = 87,
  s = 'tacos',
  b = true,
  u2, n2, i2, s2, b2;
if (typeof u2 !== 'undefined') {
  //u2 = u.toString();
}
if (n2 !== null) {
  //n2 = n.toString();
}
i2 = i.toString();
s2 = s.toString();
b2 = b.toString();
ready
toString, only when possible
var u, n = null,
  i = 87,
  s = 'tacos',
  b = true,
  u2, n2, i2, s2, b2;

i2 = i.toString();
s2 = s.toString();
b2 = b.toString();
ready
Conditional toString ('null' and 'undefined')
var u, n = null,
  i = 87,
  s = 'tacos',
  b = true,
  u2, n2, i2, s2, b2;
u2 = (typeof u2 === 'undefined') ? 'undefined' : u2.toString();
n = (n === null) ? 'null' : n.toString();
i2 = i.toString();
s2 = s.toString();
b2 = b.toString();
ready

Revisions

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