<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>performance on S Anand</title>
    <link>https://www.s-anand.net/blog/tag/performance/</link>
    <description>Recent content in performance on S Anand</description>
    <generator>Hugo -- 0.156.0</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 06 Oct 2011 13:43:22 +0000</lastBuildDate>
    <atom:link href="https://www.s-anand.net/blog/tag/performance/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Javascript arrays vs objects</title>
      <link>https://www.s-anand.net/blog/javascript-arrays-vs-objects/</link>
      <pubDate>Thu, 06 Oct 2011 13:43:22 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/javascript-arrays-vs-objects/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;: Arrays are a lot smaller than objects, but only slightly faster on newer browsers.&lt;/p&gt; &lt;p&gt;I’m writing an in-memory Javascript app that handles several thousand rows. Each row could be stored either as an array &lt;code&gt;[1,2,3]&lt;/code&gt; or an object &lt;code&gt;{&#34;x&#34;:1,&#34;y&#34;:2,&#34;z&#34;:3}&lt;/code&gt;. Having read up on the &lt;a href=&#34;http://news.qooxdoo.org/javascript-array-performance-oddities-characteristics&#34;&gt;performance of arrays vs objects&lt;/a&gt;, I thought I’d do a few tests on storing numbers from 0 to 1 million. The results for Chrome are below. (Firefox 7 was similar.)&lt;/p&gt; &lt;table style=&#34;color: #444&#34; class=&#34;numbers lines&#34;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;Time&lt;/td&gt; &lt;td&gt;Size (MB)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Array: &lt;code&gt;x[i] = i&lt;/code&gt;&lt;/td&gt; &lt;td&gt;2.44s&lt;/td&gt; &lt;td&gt;8&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Object: &lt;code&gt;x[i] = i&lt;/code&gt;&lt;/td&gt; &lt;td&gt;3.02s&lt;/td&gt; &lt;td&gt;57&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Object: &lt;code&gt;x[&#34;a_long_dummy_testing_string&#34;+i]=i&lt;/code&gt;&lt;/td&gt; &lt;td&gt;4.21s&lt;/td&gt; &lt;td&gt;238&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;The key lessons for me were:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Browsers used to process arrays MUCH faster than objects. This gap has now shrunk.&lt;/li&gt; &lt;li&gt;However, arrays are still better: not for their speed, but for their space efficiency. &lt;/li&gt; &lt;li&gt;If you’re processing a million rows or less, don’t worry about memory. If you’re storing stuff as arrays, you can store 128 columns in 1GB of RAM (1024/8=128).&lt;/li&gt;&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;dineshsaravanank&lt;/strong&gt; &lt;em&gt;11 Oct 2011 5:27 am&lt;/em&gt;:
Also, I got completely different numbers than yours. Array x[i]=i, 43ms | Object x[i]=i, 43ms | Object x[&amp;ldquo;akey&amp;rdquo;+i]=i, 2443ms. I tested in chrome, as you can see the keyed object is *significantly* slower in my case&amp;hellip;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://www.s-anand.net/&#34;&gt;S Anand&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;11 Oct 2011 10:38 pm&lt;/em&gt;:
@dinesh: When object keys are integers, browsers tend to optimise them in an array-like fashion. That explains the {1:1, 2:2} being faster than {&amp;ldquo;a1&amp;rdquo;:1,&amp;ldquo;a2&amp;rdquo;:2}.
@kalpesh, the main point of this,actually, was that performance is increasingly less of a worry for most applications. Browsers are fast enough. So the choice of language is becoming increasingly less performance driven and more ease driven.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;dineshsaravanank&lt;/strong&gt; &lt;em&gt;11 Oct 2011 5:18 am&lt;/em&gt;:
After reading this I was curious about 1) How is the read performance, 2) How does the object with long key perform.
So I ran some tests. And,
&lt;ol&gt;
&lt;li&gt;as expected reads are much faster than the writes and there is no significant difference between array and object when it came to read.&lt;/li&gt;
&lt;li&gt;Longer keys take more time to execute, smaller keys are significantly faster than very long keys. But there are some surprises here. An object {&amp;ldquo;1&amp;rdquo;:1,&amp;ldquo;2&amp;rdquo;:2,&amp;ldquo;3&amp;rdquo;:3} is much faster than {&amp;ldquo;a1&amp;rdquo;:1, &amp;ldquo;a2&amp;rdquo;:2, &amp;ldquo;a3&amp;rdquo;:4}, while object {&amp;ldquo;a1&amp;rdquo;:1,&amp;ldquo;a2&amp;rdquo;:2} and object {&amp;ldquo;alittlelong1&amp;rdquo;:1, &amp;ldquo;alittlelong2&amp;rdquo;:2} are almost same.
You can see the tests here &lt;a href=&#34;http://jsfiddle.net/ETAb9/&#34;&gt;http://jsfiddle.net/ETAb9/&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Kalpesh&lt;/strong&gt; &lt;em&gt;12 Oct 2011 4:56 pm&lt;/em&gt;:
I agree. My question was to think of it, in terms of memory consumption.
Your thoughts?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Kalpesh&lt;/strong&gt; &lt;em&gt;10 Oct 2011 10:50 am&lt;/em&gt;:
Considering this, do you think OO based languages add overhead to space it occupies when run, in memory?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://www.arunrocks.com&#34;&gt;Arun&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;13 Oct 2011 6:09 pm&lt;/em&gt;:
Anand,
This is because &lt;strong&gt;object&lt;/strong&gt; is a fundamental data type in Javascript and an &lt;strong&gt;Array&lt;/strong&gt; is implemented as a special kind of &lt;strong&gt;object&lt;/strong&gt;. Hence the lookups (the Time column) would be implemented as a hash map lookup in both cases.
However the storage could be an interesting case. As one of the early gotchas of Javascript teaches us:
&lt;code&gt;Person.Name&lt;/code&gt; is equivalent to &lt;code&gt;Person[&#39;Name&#39;]&lt;/code&gt;
But in the case of Array&amp;rsquo;s some magic is applied leading to optimisations in storage. Hence I suppose rather than storing unicode strings for &amp;ldquo;0&amp;rdquo;, &amp;ldquo;1&amp;rdquo; etc., they are stored as integers.
Javascript, like English, is berry phunny language :)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Joe&lt;/strong&gt; &lt;em&gt;29 Feb 2016 1:02 pm&lt;/em&gt;:
I ran some tests and was surprised that array access is only slightly faster. Something strange has to be going on with that. My test compares numeric entries either way. The object implementation normally has the extra work of casting to string and hashing. I have a feeling it will be different with non-numeric versus numeric keys. Still, it hints at something strange going on.&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Google Calendar released</title>
      <link>https://www.s-anand.net/blog/google-calendar-released/</link>
      <pubDate>Thu, 13 Apr 2006 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/google-calendar-released/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://calendar.google.com/&#34;&gt;Google Calendar&lt;/a&gt; is out. But for some reason, it&amp;rsquo;s too slow for me.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Dhar&lt;/strong&gt; &lt;em&gt;13 Apr 2006 8:08 am&lt;/em&gt;:
You are right. It was too frigging slow in the beginning. But after the initial wait, things worked out. :))&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Krishna&lt;/strong&gt; &lt;em&gt;15 Apr 2006 5:48 pm&lt;/em&gt;:
Do you still see it being slow?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;S Anand&lt;/strong&gt; &lt;em&gt;16 Apr 2006 6:45 am&lt;/em&gt;:
It loads slowly, but is OK now. I&amp;rsquo;m having problems importing data in the iCal format, though.&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Gmail is fast</title>
      <link>https://www.s-anand.net/blog/gmail-is-fast/</link>
      <pubDate>Mon, 29 Aug 2005 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/gmail-is-fast/</guid>
      <description>&lt;p&gt;As Jeremy put it, &lt;a href=&#34;http://jeremy.zawodny.com/blog/archives/004689.html&#34;&gt;GMail is really damn fast. Faster than desktop email.&lt;/a&gt; I prefer it to Outlook, and hence to my work e-mail ID.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>100m record is broken</title>
      <link>https://www.s-anand.net/blog/100m-record-is-broken/</link>
      <pubDate>Mon, 16 Sep 2002 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/100m-record-is-broken/</guid>
      <description>&lt;p&gt;The world&amp;rsquo;s &lt;a href=&#34;http://news.bbc.co.uk/sport1/hi/athletics/2259347.stm&#34;&gt;100m record is broken&lt;/a&gt;. Without drugs, this time. At 9.78 seconds, Montgomery has been running at over 35 km per hour. I used to drive that fast, on average.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>PC Pit Stop</title>
      <link>https://www.s-anand.net/blog/pc-pit-stop/</link>
      <pubDate>Sat, 27 Jul 2002 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/pc-pit-stop/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://www.pcpitstop.com&#34;&gt;PC Pit Stop&lt;/a&gt;. A good tune-up for your PC. I managed to improve my hard disk performance by enabling DMA, and my memory by reducing the video card shared memory.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Performance based pay for Governments</title>
      <link>https://www.s-anand.net/blog/performance-based-pay-for-governments/</link>
      <pubDate>Sat, 27 Jan 2001 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/performance-based-pay-for-governments/</guid>
      <description>&lt;p&gt;Even states have &lt;a href=&#34;http://www.timesofindia.com/270101/27busi2.htm&#34;&gt;performance based pay&lt;/a&gt;. The less their fiscal deficit, the more their plan allocation. Good.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Phantom of the Opera</title>
      <link>https://www.s-anand.net/blog/phantom-of-the-opera/</link>
      <pubDate>Tue, 17 Oct 2000 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/phantom-of-the-opera/</guid>
      <description>&lt;p&gt;There&amp;rsquo;s a stall that sells theatre tickets for &lt;a href=&#34;http://www.officiallondontheatre.co.uk/booth.cfm&#34;&gt;half price at Leicester Square&lt;/a&gt;, so I went there in the morning. It opened only at 12 noon, so rather than waiting, I just bought tickets for the balcony. 15.50 pounds didn&amp;rsquo;t seem to much. The musical was &amp;ldquo;The Phantom of the Opera&amp;rdquo;, running at Her Majesty&amp;rsquo;s Theatre.&lt;/p&gt;
&lt;p&gt;There were 6 of us, and we went to the show. That was when I realized why the tickets were so cheap. They were on the second row of the third floor. Which meant that we had to crane our necks to see anything. What made it worse was that the lady in front of me refused to sit still. But after a while, I got used to it.&lt;/p&gt;
&lt;p&gt;Well, one can see why it&amp;rsquo;s been running house full for the last 10-15 years. The visual effects are amazing. The play begins with an auction of a chandelier which fell during a performance at an opera in France. It is rumoured that the chandelier was caused to fall by the &amp;lsquo;Phantom of the Opera&amp;rsquo;. We go back in time (special effects). There&amp;rsquo;s this girl who&amp;rsquo;s been learning music from the Phantom, and he loves her, but she loves Raoul, who loves her. So the Phantom is angry, and does bad things, but finally gets a bout of conscience and unites them. That&amp;rsquo;s the plot.&lt;/p&gt;
&lt;p&gt;But you wouldn&amp;rsquo;t think it when watching the show. The music is spell-binding, and performed real-time. When the Phantom takes Catherine to his den, they row over a lake made of smoke. Near Catherine&amp;rsquo;s father&amp;rsquo;s grave, there&amp;rsquo;s a lovely effect of water puddles. At this point, the Phantom appears and there&amp;rsquo;s some great fireworks also. What&amp;rsquo;s even more impressive is the coordination of the staff to get all these HUGE sets in place from scene to scene. The largest was a huge staircase, which must have weighed several tonnes. Sure, they must have had wheels. But still, it&amp;rsquo;s a feat to marvel at. Put all this in with the music, and you get an experience that&amp;rsquo;s more gripping than any movie that I&amp;rsquo;ve seen. The 3 hours flew by like the blink of an eyelid.&lt;/p&gt;
&lt;p&gt;Well, not quite. Although I felt myself in the 17th century right through, there was one small interruption. Towards the end, when Christine was softly sobbing to Raoul, the atmosphere was broken by the ring of a mobile. That moment was almost like snapping back from a vision to reality.&lt;/p&gt;
&lt;p&gt;Now, how can I stop myself from seeing &amp;ldquo;The Lion King&amp;rdquo;?&lt;/p&gt;
</description>
    </item>
  </channel>
</rss>
