ただのオブジェクトに比べて、50倍くらい時間がかかる。
Vimperator でテスト。
テストコード
let time = function (name, func) { let [a, r, b] = [new Date(), func(), new Date()]; log(name + ": " + ((b.getTime() - a.getTime()) / 1000) + "msec"); return r; } time('object - getter', function () { let ary = []; for (let i = 0; i < 70000; i++) { ary.push({ url: 'neko', title: 'sippo', get icon() function() bookmarks.getFavicon(this.url) }); } }); time('object - property', function () { let ary = []; for (let i = 0; i < 70000; i++) { ary.push({ url: 'neko', title: 'sippo', icon: function() bookmarks.getFavicon(this.url) }); } }); time('array', function () { let ary = []; for (let i = 0; i < 70000; i++) { ary.push(['neko', 'sippo', function() bookmarks.getFavicon(this.url)]); } });
出力
vimperator: array: 0.079msec vimperator: object - property: 0.056msec vimperator: object - getter: 3.078msec