Tuples vs Objects

JavaScript performance comparison

Test case created by Dennis Torres

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var serviceNames = [
    'Facebook',
    'Flickr',
    'GameCenter',
    'LinkedIn',
    'MySpace',
    'SinaWeibo',
    'TencentWeibo',
    'Twitter',
    'Yelp'
  ];
  
  var serviceUrls = [
    'https://www.facebook.com',
    'https://flickr.com/user',
    'https://apple.gamecenter.com/user',
    'https://www.linkedin.com/user',
    'https://www.myspace.com/user',
    'https://www.sina.weibo.com/user',
    'https://www.tencent.weibo.com/user',
    'https://twitter.com',
    'https://www.yelp.com/user'
  ];
  
  var tupleArray = [];
  var objectArray = [];
  
  for (var i = 0; i < 1000; i++) {
    var username = 'user' + i;
    var userId = 'some-random-stuff-' + i;
    var serviceName = serviceNames[i % serviceNames.length];
    var url = serviceUrls[i % serviceUrls.length] + '/' + username;
    tupleArray.push([serviceName, username, url, userId]);
    objectArray.push({ serviceName: serviceName, username: username, userId: userId, url: url });
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Tuples
// async test
tupleArray.forEach(function (tuple) {
  console.log(tuple[0]);
  console.log(tuple[1]);
  console.log(tuple[2]);
  console.log(tuple[3]);
});

deferred.resolve();
pending…
Objects
objectArray.forEach(function (object) {
  console.log(object.serviceName);
  console.log(object.username);
  console.log(object.url);
  console.log(object.userId);
});

deferred.resolve();
pending…

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

0 Comments