<?xml version="1.0"?>
<!-- name="generator" content="bloxsom/0+3i" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
  <channel>
    <title>Christian Simms's Software R&amp;D</title>
    <link>http://simmsland.com/blog/2003/May/31/xml</link>
    <description>Generative Programming and other R&amp;D.</description>
    <language>en</language>
  <item>
    <title>In my spare time, I've been developing a J2EE code generator using python.</title>
    <link>http://simmsland.com/blog/2003/May/31/xml/2003/May/31#perf-test</link>
    <description>However, I noticed that as I added new features, the performance was degrading
considerably, so I decided to do some benchmarks.  This is what I found.

&lt;p/&gt;
Below, each column name is a link to the source code for the given language.
Each program is written in the style for that language, so for instance the Python
version uses the built-in dictionary for hash tables, whereas the Java version uses
HashMap class. Notice how these tests don't do something simple like test
using hashes of int's, because I haven't had to do that kind of thing since college.
&lt;p/&gt;

&lt;table border=&quot;1&quot;&gt;
  &lt;tr&gt;
    &lt;td&gt; Test &lt;/td&gt;
    &lt;td&gt; &lt;a href=&quot;/blog/perf.py&quot;&gt;Python&lt;/a&gt; &lt;/td&gt;
    &lt;td&gt; &lt;a href=&quot;/blog/perf.java&quot;&gt;Java (classic) &lt;/a&gt; &lt;/td&gt;
    &lt;td&gt; &lt;a href=&quot;/blog/perf.java&quot;&gt;Java (hotspot) &lt;/a&gt; &lt;/td&gt;
    &lt;td&gt; &lt;a href=&quot;/blog/perf.cs&quot;&gt;C# &lt;/a&gt; &lt;/td&gt;
    &lt;td&gt; &lt;a href=&quot;/blog/perf.cpp&quot;&gt;g++ &lt;/a&gt; &lt;/td&gt;
    &lt;td&gt; &lt;a href=&quot;/blog/perf.cpp&quot;&gt;g++ (-O3) &lt;/a&gt; &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt; Dynamic Object Allocation &lt;/td&gt;
    &lt;td&gt; 141,000/sec &lt;/td&gt;
    &lt;td&gt; 168,000/sec &lt;/td&gt;
    &lt;td&gt; 1,400,000/sec &lt;/td&gt;
    &lt;td&gt; 52,300,000/sec &lt;/td&gt;
    &lt;td&gt; 1,060,000/sec &lt;/td&gt;
    &lt;td&gt; 1,450,000/sec &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt; Dynamic Object Allocation plus hash table get/set &lt;/td&gt;
    &lt;td&gt; 9,880/sec &lt;/td&gt;
    &lt;td&gt; 4,670/sec &lt;/td&gt;
    &lt;td&gt; 56,300/sec &lt;/td&gt;
    &lt;td&gt; 53,800/sec &lt;/td&gt;
    &lt;td&gt; 19,100/sec &lt;/td&gt;
    &lt;td&gt; 30,200/sec &lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;p/&gt;

So what can we learn from this?
&lt;ul&gt;
&lt;li&gt; Java with hotspot compares favorably to C# &lt;/li&gt;
&lt;li&gt; Java with hotspot is something like 10x faster than without &lt;/li&gt;
&lt;li&gt; Python's about 5x slower than Java/C# &lt;/li&gt;
&lt;li&gt; And most surprising (to me): Java and C# were both about twice as fast as C++! I had read that could be true, but seeing is believing. &lt;/li&gt;
&lt;/ul&gt;

I tried speeding up the Python code using the &lt;a href=&quot;http://psyco.sourceforge.net/index.html&quot;&gt;Psycho&lt;/a&gt; JIT compiler,
but without much luck.  Actually, it was slightly slower (maybe 10% slower), and I think I know why. The Python versions
of these tests primarily test the memory allocator and built-in dictionary type, neither of which can be JIT'ed because
they're already native in the Python language, so I just saw the overhead of the JIT).
</description>
  </item>
  </channel>
</rss>