Cast To String (v17)

Revision 17 of this benchmark created 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 u !== 'undefined') {
  //u2 = u.toString();
}
if (n !== 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;
//u2 = u.toString(); //not possible
//n2 = n.toString(); //not possible
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 u === 'undefined') ? 'undefined' : u.toString();
n2 = (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.