LoginSignup
0
0

More than 5 years have passed since last update.

「array.pushが遅い」という記事を見かけたので試してみた

Posted at

検証コード

javascript
(function() {
  console.time('push');
  var array = [];
  for (var i=0;i<100000000;i++) {
    array.push(i);
  }
  console.timeEnd('push');
})();

(function() {
  console.time('length');
  var array = [];
  for (var i=0;i<100000000;i++) {
    array[array.length] = i;
  }
  console.timeEnd('length');
})();

結果

Chrome 51.0.2704.63 (64-bit)
push: 1577.093ms
length: 1537.691ms

Firefox 46.0.1
push: 1812.18ms
length: 1866.65ms

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0