Using methods on primitive type

Benchmark created by Vojta on


Description

Compare using primitive string type vs string object. Based on http://dev.opera.com/articles/view/efficient-javascript/

Setup

var primitiveStr = 'some string...';
    var objectStr = new String('some string...');

Test runner

Ready to run.

Testing in
TestOps/sec
Primitive type
var temp;
for (var i = 0; i < primitiveStr.length; i++) {
  temp = primitiveStr.charAt(i);
}
ready
String object
var temp;
for (var i = 0; i < objectStr.length; i++) {
  temp = objectStr.charAt(i);
}
ready
Primitive type - index access
var temp;
for (var i = 0; i < primitiveStr.length; i++) {
  temp = primitiveStr[i];
}
ready
String object - index access
var temp;
for (var i = 0; i < objectStr.length; i++) {
  temp = objectStr[i];
}
ready

Revisions

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

  • Revision 1: published by Vojta on