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'
  ];

};
</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
var objectArray2 = [];

for (var i = 0; i < 10000; i++) {
  var username = 'user' + i;
  var userId = 'some-random-stuff-' + i;
  var serviceName = serviceNames[i % serviceNames.length];
  var url = serviceUrls[i % serviceUrls.length] + '/' + username;
  objectArray2.push({ serviceName: serviceName, username: username, userId: userId, url: url });
}
pending…
Objects
var objectArray1 = [];

for (var i = 0; i < 10000; i++) {
  var username = 'user' + i;
  var userId = 'some-random-stuff-' + i;
  var serviceName = serviceNames[i % serviceNames.length];
  var url = serviceUrls[i % serviceUrls.length] + '/' + username;
  objectArray1.push({ a1: serviceName, b2: username, c3: userId, d4: url });
}
pending…

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

0 Comments