Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Accessing object properties and array elements in JavaScript is syntacticly assumed to be done in <a href="http://en.wikipedia.org/wiki/Time_complexity#Constant_time" rel="noreferrer">constant time</a>: O(1). Performance characteristics are not guaranteed in the ECMAScript specification, but all the modern JavaScript engines retrieve object properties in constant time.</p> <p>Here's a simple example showing how access times grow when the container is x1000 times bigger:</p> <pre><code>var largeObject = {}; var smallObject = {}; var x, i; for (i = 0; i &lt; 1000000; i++) { largeObject['a' + i] = i; } for (i = 0; i &lt; 1000; i++) { smallObject['b' + i] = i; } console.time('10k Accesses from largeObject'); for (i = 0; i &lt; 10000; i++) x = largeObject['a' + (i % 1000000)]; console.timeEnd('10k Accesses from largeObject'); console.time('10k Accesses from smallObject'); for (i = 0; i &lt; 10000; i++) x = largeObject['a' + (i % 1000)]; console.timeEnd('10k Accesses from smallObject'); </code></pre> <p>Results in Firebug, Firefox 3.6.10 (Mac OS X 10.6.4 - 2.93Ghz Intel Core 2 Duo):</p> <pre><code>10k Accesses from largeObject: 22ms 10k Accesses from smallObject: 19ms </code></pre> <p>Results in Chrome Dev Tools 6.0.472:</p> <pre><code>10k Accesses from largeObject: 15ms 10k Accesses from smallObject: 15ms </code></pre> <p>Internet Explorer 8.0.7600 with Firebug Lite on Windows 7</p> <pre><code>10k Accesses from largeObject: 250ms 10k Accesses from smallObject: 219ms </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload