Ferrous Moon http://www.ferrousmoon.com:80/forums/ |
|
Programming Language Performance http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=1580 |
Page 1 of 5 |
Author: | Tycho [Tue Nov 11, 2008 4:00 am ] |
Post subject: | Programming Language Performance |
I decided to write GenPrime in C, Java, Perl, PHP, Python, and Ruby. I used essentially the same code in every language, adapted for that particular language's syntax. I chose to avoid any special performance tricks to give any language a special advantage (i.e. psyco for Python), just keeping to the most simple code possible. The host machine is a MacBook Pro, 2.33GHz Intel Core 2 Duo. It's running Mac OS X 10.5.5 for these tests. I ran all the tests at the highest possible priority (process priority -20). First of all, here's the various interpreter/compiler versions: Code: Alcarin:genprime steven$ make version
gcc -v
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5488~2/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5488)
java -version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)
perl -v | grep built\ for
This is perl, v5.8.8 built for darwin-2level
php --version
PHP 5.2.6 (cli) (built: Jul 17 2008 23:04:49)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
python --version
Python 2.5.1
ruby --version
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
And here are the timings. Code: genprime (C)
Found 50000 primes in 0.19841 seconds
Found 100000 primes in 0.50931 seconds
Found 150000 primes in 0.92027 seconds
Found 200000 primes in 1.40240 seconds
Found 250000 primes in 1.94638 seconds
Found 300000 primes in 2.54913 seconds
Found 350000 primes in 3.18607 seconds
Found 400000 primes in 3.87813 seconds
Found 450000 primes in 4.60960 seconds
Found 500000 primes in 5.37480 seconds
genprime (Java)
Found 50000 primes in 0.73692 seconds
Found 100000 primes in 2.05211 seconds
Found 150000 primes in 3.75281 seconds
Found 200000 primes in 5.75766 seconds
Found 250000 primes in 8.02739 seconds
Found 300000 primes in 10.54028 seconds
Found 350000 primes in 13.49219 seconds
Found 400000 primes in 16.23506 seconds
Found 450000 primes in 19.34955 seconds
Found 500000 primes in 22.78697 seconds
genprime (Perl)
Found 50000 primes in 5.40779 seconds
Found 100000 primes in 14.69201 seconds
Found 150000 primes in 26.49082 seconds
Found 200000 primes in 40.37200 seconds
Found 250000 primes in 56.08549 seconds
Found 300000 primes in 73.35086 seconds
Found 350000 primes in 92.07987 seconds
Found 400000 primes in 112.32640 seconds
Found 450000 primes in 133.71009 seconds
Found 500000 primes in 155.97158 seconds
genprime (PHP)
Found 50000 primes in 4.00840 seconds
Found 100000 primes in 11.07893 seconds
Found 150000 primes in 20.21437 seconds
Found 200000 primes in 30.67449 seconds
Found 250000 primes in 42.16837 seconds
Found 300000 primes in 55.41089 seconds
Found 350000 primes in 69.64593 seconds
Found 400000 primes in 85.05749 seconds
Found 450000 primes in 101.41554 seconds
Found 500000 primes in 118.27612 seconds
genprime (Python)
Found 50000 primes in 4.88558 seconds
Found 100000 primes in 13.60224 seconds
Found 150000 primes in 24.77291 seconds
Found 200000 primes in 37.77130 seconds
Found 250000 primes in 52.79973 seconds
Found 300000 primes in 68.40338 seconds
Found 350000 primes in 85.96679 seconds
Found 400000 primes in 106.78055 seconds
Found 450000 primes in 127.79205 seconds
Found 500000 primes in 150.53608 seconds
genprime (Ruby)
Found 50000 primes in 0.41741 seconds
Found 100000 primes in 1.03021 seconds
Found 150000 primes in 1.75972 seconds
Found 200000 primes in 2.57720 seconds
Found 250000 primes in 3.46559 seconds
Found 300000 primes in 4.41411 seconds
Found 350000 primes in 5.42736 seconds
Found 400000 primes in 6.53082 seconds
Found 450000 primes in 7.62712 seconds
Found 500000 primes in 8.79880 seconds
So basically, the best to worst performance order is this:C, Ruby, Java, PHP, Python, Perl. Using Psyco on the Python version, the order would change to: C, Ruby, Java, Python, PHP, Perl. If you want the source for all the versions, it's all available in a [url=git://github.com/tycho/genprime.git]Git repository[/url] graciously hosted by github.com. EDIT: Whoops, random incomplete sentence in there. |
Author: | Tycho [Tue Nov 11, 2008 8:14 am ] |
Post subject: | Re: Programming Language Performance |
Added C++, C#, and Objective-C. I would be very interested if someone wrote one in a functional or purely functional language (Common Lisp, Haskell, etc). Here's the added version information: Code: Alcarin:genprime steven$ make version
gmcs --version
Mono C# compiler version 2.0.1.0
mono --version
Mono JIT compiler version 2.0.1 (tarball)
Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.com
TLS: normal
GC: Included Boehm (with typed GC)
SIGSEGV: normal
Notification: Thread + polling
Architecture: x86
Disabled: none
g++ -v
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5488~2/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5488)
And here are the timings:
Code: genprime (C++)
Found 50000 primes in 0.18520 seconds
Found 100000 primes in 0.50844 seconds
Found 150000 primes in 0.91678 seconds
Found 200000 primes in 1.39666 seconds
Found 250000 primes in 1.93729 seconds
Found 300000 primes in 2.53311 seconds
Found 350000 primes in 3.17518 seconds
Found 400000 primes in 3.86686 seconds
Found 450000 primes in 4.63069 seconds
Found 500000 primes in 5.41091 seconds
genprime (C#)
Found 50000 primes in 0.97620 seconds
Found 100000 primes in 3.72235 seconds
Found 150000 primes in 8.76363 seconds
Found 200000 primes in 16.53498 seconds
Found 250000 primes in 27.49357 seconds
Found 300000 primes in 41.98351 seconds
Found 350000 primes in 59.97110 seconds
Found 400000 primes in 81.90829 seconds
Found 450000 primes in 108.09789 seconds
Found 500000 primes in 138.76492 seconds
genprime (Objective-C)
Found 50000 primes in 0.19406 seconds
Found 100000 primes in 0.52914 seconds
Found 150000 primes in 0.95275 seconds
Found 200000 primes in 1.44969 seconds
Found 250000 primes in 2.00885 seconds
Found 300000 primes in 2.62542 seconds
Found 350000 primes in 3.29183 seconds
Found 400000 primes in 4.00716 seconds
Found 450000 primes in 4.76640 seconds
Found 500000 primes in 5.56732 seconds
|
Author: | Tycho [Tue Nov 11, 2008 9:07 am ] |
Post subject: | Re: Programming Language Performance |
Added JavaScript implementation. This one is trickier than the others, because nearly every browser has its own implementation of JavaScript (which makes the timings vary wildly). For this test, I'm using WebKit nightly (r38297): Code: genprime (JavaScript)
Found 25000 primes in 0.158 seconds
Found 50000 primes in 0.434 seconds
Found 75000 primes in 0.785 seconds
Found 100000 primes in 1.198 seconds
Found 125000 primes in 1.662 seconds
Found 150000 primes in 2.182 seconds
Found 175000 primes in 2.737 seconds
Found 200000 primes in 3.336 seconds
Found 225000 primes in 3.965 seconds
Found 250000 primes in 4.631 seconds
You'll note that I used a different test interval. That's because if a particular script takes too long, Safari decides to halt the JavaScript execution and ask the user if the script should be terminated. Unfortunately, halting the script also totally blows the timings. I decided to use power regression to predict what the results would be with a full run. Here's the prediction (r-squared is 0.9999898):Code: genprime (JavaScript)
Found 50000 primes in 0.434 seconds
Found 100000 primes in 1.203 seconds
Found 150000 primes in 2.181 seconds
Found 200000 primes in 3.328 seconds
Found 250000 primes in 4.618 seconds
Found 300000 primes in 6.036 seconds
Found 350000 primes in 7.569 seconds
Found 400000 primes in 9.208 seconds
Found 450000 primes in 10.946 seconds
Found 500000 primes in 12.778 seconds
Not bad for a JavaScript interpreter. Hell, it even beats Java, and Java's the prettier cousin!EDIT: I also tested on Safari's current release version (v3.1.2). The results weren't quite as invigorating: Code: genprime (JavaScript)
Found 10000 primes in 0.284 seconds
Found 20000 primes in 0.748 seconds
Found 30000 primes in 1.339 seconds
Found 40000 primes in 2.04 seconds
Found 50000 primes in 2.821 seconds
Found 60000 primes in 3.699 seconds
Found 70000 primes in 4.619 seconds
Found 80000 primes in 5.639 seconds
Found 90000 primes in 6.696 seconds
Found 100000 primes in 8.034 seconds
I had to use an even smaller interval, because Safari 3.1.2 doesn't use the new SquirrelFish Extreme engine that's in the WebKit nightlies. Okay, statistical projection time (r-squared: 0.9997743):Code: genprime (JavaScript)
Found 50000 primes in 2.852 seconds
Found 100000 primes in 7.787 seconds
Found 150000 primes in 14.013 seconds
Found 200000 primes in 21.261 seconds
Found 250000 primes in 29.378 seconds
Found 300000 primes in 38.261 seconds
Found 350000 primes in 47.838 seconds
Found 400000 primes in 58.050 seconds
Found 450000 primes in 68.854 seconds
Found 500000 primes in 80.211 seconds
Still not nearly as bad as PHP, Python, Perl, etc. But SquirrelFish is certainly less speedy than SquirrelFish Extreme!
|
Author: | Chase [Tue Nov 11, 2008 9:21 am ] |
Post subject: | Re: Programming Language Performance |
Quote: Not bad for a JavaScript interpreter. Hell, it even beats Java, and Java's the prettier cousin!
Javascript also has ALOT less overhead. However that is interesting, perhaps try it on other browsers like opera, mozilla and ie. I think webkit uses a JIT for js.I would write a copy in bf but its tentively limited to numbers up to 255 on a standard interpreter and restricted to the interpreter its run on. (I could work around this but that code is huge, and my sqrt routine still needs some work) |
Author: | Tycho [Tue Nov 11, 2008 9:32 am ] |
Post subject: | Re: Programming Language Performance |
Here's Camino 1.6.4 (Mozilla's Mac-only browser). I would suspect that the results would be the same on Firefox, SeaMonkey, etc. Code: genprime (JavaScript)
Found 10000 primes in 0.319 seconds
Found 20000 primes in 0.889 seconds
Found 30000 primes in 1.601 seconds
Found 40000 primes in 2.437 seconds
Found 50000 primes in 3.376 seconds
Found 60000 primes in 4.412 seconds
Found 70000 primes in 5.544 seconds
Found 80000 primes in 6.744 seconds
Found 90000 primes in 8.053 seconds
Found 100000 primes in 9.41 seconds
Had to statistically predict this one too (r-squared: 0.99998968):Code: genprime (JavaScript)
Found 50000 primes in 3.389 seconds
Found 100000 primes in 9.370 seconds
Found 150000 primes in 16.987 seconds
Found 200000 primes in 25.908 seconds
Found 250000 primes in 35.944 seconds
Found 300000 primes in 46.969 seconds
Found 350000 primes in 58.891 seconds
Found 400000 primes in 71.638 seconds
Found 450000 primes in 85.153 seconds
Found 500000 primes in 99.390 seconds
|
Author: | Miah [Tue Nov 11, 2008 9:37 am ] |
Post subject: | Re: Programming Language Performance |
I shudder to think of what IE would do. I have IE6 on this machine (I call it the FailBox, because if anything will break, it'll break here). I'll do a rendition for it. |
Author: | Tycho [Tue Nov 11, 2008 12:15 pm ] |
Post subject: | Re: Programming Language Performance |
Quote: I shudder to think of what IE would do.
Well, I've tested IE6 and IE7 now. They performed identically.
Code: genprime (JavaScript)
Found 10000 primes in 0.812 seconds
Found 20000 primes in 2.172 seconds
Found 30000 primes in 3.781 seconds
Found 40000 primes in 5.641 seconds
Found 50000 primes in 7.813 seconds
Found 60000 primes in 10.141 seconds
Found 70000 primes in 12.484 seconds
Found 80000 primes in 15.125 seconds
Found 90000 primes in 17.953 seconds
Found 100000 primes in 20.844 seconds
And here's the power regression (r-squared: 0.99996127):
Code: genprime (JavaScript)
Found 50000 primes in 7.814 seconds
Found 100000 primes in 20.731 seconds
Found 150000 primes in 36.685 seconds
Found 200000 primes in 54.999 seconds
Found 250000 primes in 75.296 seconds
Found 300000 primes in 97.327 seconds
Found 350000 primes in 120.913 seconds
Found 400000 primes in 145.917 seconds
Found 450000 primes in 172.231 seconds
Found 500000 primes in 199.766 seconds
Eeegh.I'm going to try IE8 and Chrome in a bit. As well as Firefox (on Windows). |
Author: | Tycho [Tue Nov 11, 2008 12:31 pm ] |
Post subject: | Re: Programming Language Performance |
Whee, IE8 is even worse. Code: genprime (JavaScript)
Found 10000 primes in 0.735 seconds
Found 20000 primes in 2.063 seconds
Found 30000 primes in 3.671 seconds
Found 40000 primes in 5.703 seconds
Found 50000 primes in 7.937 seconds
Found 60000 primes in 10.203 seconds
Found 70000 primes in 12.922 seconds
Found 80000 primes in 15.735 seconds
Found 90000 primes in 18.688 seconds
Found 100000 primes in 21.625 seconds
Power regression (r-squared is 0.99995483):
Code: genprime (JavaScript)
Found 50000 primes in 7.865 seconds
Found 100000 primes in 21.784 seconds
Found 150000 primes in 39.535 seconds
Found 200000 primes in 60.342 seconds
Found 250000 primes in 83.766 seconds
Found 300000 primes in 109.510 seconds
Found 350000 primes in 137.358 seconds
Found 400000 primes in 167.146 seconds
Found 450000 primes in 198.739 seconds
Found 500000 primes in 232.028 seconds
|
Author: | Tycho [Tue Nov 11, 2008 12:39 pm ] |
Post subject: | Re: Programming Language Performance |
Here's Chrome v0.3.154.9: Code: genprime (JavaScript)
Found 50000 primes in 0.305 seconds
Found 100000 primes in 0.825 seconds
Found 150000 primes in 1.475 seconds
Found 200000 primes in 2.259 seconds
Found 250000 primes in 3.142 seconds
Found 300000 primes in 4.099 seconds
Found 350000 primes in 5.131 seconds
Found 400000 primes in 6.261 seconds
Found 450000 primes in 7.473 seconds
Found 500000 primes in 8.713 seconds
Looks like Chrome's JavaScript engine is indeed as good as is claimed. It beats WebKit (by a somewhat small margin which will no doubt close with time).
|
Author: | Chase [Tue Nov 11, 2008 2:25 pm ] |
Post subject: | Re: Programming Language Performance |
You can easily grab a copy of the Mac Opera and test it there, see how it preforms on thier ECMAScript engine (aparently Javascript just wasn't good enough). If you use dragonfly (built in developer tool), you might be able to run the full test on it. |
Author: | prophile [Wed Nov 12, 2008 6:40 pm ] |
Post subject: | Re: Programming Language Performance |
Any chance of an assembly language run for reference? |
Author: | Tycho [Thu Nov 13, 2008 12:04 am ] |
Post subject: | Re: Programming Language Performance |
Quote: Any chance of an assembly language run for reference?
See the 'C' example. Also, I don't intend to write a handcoded ASM one. I might take the compiled C one and hand-optimize it, though.
|
Author: | sithid [Thu Nov 13, 2008 7:09 am ] |
Post subject: | Re: Programming Language Performance |
I ran your C# version on my comp and it ran alot faster( maybe mono is slower *shrugs* ). WinXP Pro, 2.20Ghz Intel Core 2 Duo Quote:
C:\Documents and Settings\Sithid\My Documents\Visual Studio 2008\Projects\Logic\
Logic\bin\Debug>Logic.exe 50000 500000 Found 50000 primes in 0.31454 seconds (last was 611953) Found 100000 primes in 1.03767 seconds (last was 1299709) Found 150000 primes in 2.34907 seconds (last was 2015177) Found 200000 primes in 4.42103 seconds (last was 2750159) Found 250000 primes in 7.22041 seconds (last was 3497861) Found 300000 primes in 10.87515 seconds (last was 4256233) Found 350000 primes in 15.51989 seconds (last was 5023307) Found 400000 primes in 21.11358 seconds (last was 5800079) Found 450000 primes in 27.80042 seconds (last was 6581963) Found 500000 primes in 35.63230 seconds (last was 7368787) Quote:
C:\Documents and Settings\Sithid\My Documents\Visual Studio 2008\Projects\Logic\
Logic\bin\Release>Logic.exe 50000 500000 Found 50000 primes in 0.26910 seconds (last was 611953) Found 100000 primes in 0.86832 seconds (last was 1299709) Found 150000 primes in 1.93147 seconds (last was 2015177) Found 200000 primes in 3.55834 seconds (last was 2750159) Found 250000 primes in 5.86121 seconds (last was 3497861) Found 300000 primes in 8.83177 seconds (last was 4256233) Found 350000 primes in 12.45281 seconds (last was 5023307) Found 400000 primes in 16.88923 seconds (last was 5800079) Found 450000 primes in 22.12241 seconds (last was 6581963) Found 500000 primes in 28.26553 seconds (last was 7368787) |
Author: | Tycho [Thu Nov 13, 2008 12:53 pm ] |
Post subject: | Re: Programming Language Performance |
I suspect Mono is indeed slower. I'm going to run it on Windows using Microsoft's C# compiler in a bit. |
Author: | Tycho [Thu Nov 13, 2008 10:57 pm ] |
Post subject: | Re: Programming Language Performance |
So apparently Ruby isn't as fast as I thought. I added some debugging output (shows the last prime calculated on each final iteration), and discovered that Ruby was thinking -every number- was prime. So yeah. Here are the new results: Code: genprime (C)
Found 250000 primes in 2.03855 seconds (last was 3497861)
Found 500000 primes in 5.69525 seconds (last was 7368787)
Found 750000 primes in 10.32096 seconds (last was 11381621)
Found 1000000 primes in 15.84383 seconds (last was 15485863)
genprime (C LLVM)
Found 250000 primes in 2.00452 seconds (last was 3497861)
Found 500000 primes in 5.58073 seconds (last was 7368787)
Found 750000 primes in 10.56258 seconds (last was 11381621)
Found 1000000 primes in 16.97467 seconds (last was 15485863)
genprime (C LLVM JIT)
Found 250000 primes in 2.00863 seconds (last was 3497861)
Found 500000 primes in 5.66369 seconds (last was 7368787)
Found 750000 primes in 10.37664 seconds (last was 11381621)
Found 1000000 primes in 15.89380 seconds (last was 15485863)
genprime (C Clang/LLVM)
Found 250000 primes in 1.95876 seconds (last was 3497861)
Found 500000 primes in 5.45282 seconds (last was 7368787)
Found 750000 primes in 10.05708 seconds (last was 11381621)
Found 1000000 primes in 15.72205 seconds (last was 15485863)
genprime (C Clang/LLVM JIT)
Found 250000 primes in 2.47696 seconds (last was 3497861)
Found 500000 primes in 7.08403 seconds (last was 7368787)
Found 750000 primes in 11.12229 seconds (last was 11381621)
Found 1000000 primes in 16.84753 seconds (last was 15485863)
genprime (C++)
Found 250000 primes in 2.01354 seconds (last was 3497861)
Found 500000 primes in 5.62421 seconds (last was 7368787)
Found 750000 primes in 10.20536 seconds (last was 11381621)
Found 1000000 primes in 15.61217 seconds (last was 15485863)
genprime (C#)
Found 250000 primes in 10.84425 seconds (last was 3497861)
Found 500000 primes in 41.89792 seconds (last was 7368787)
Found 750000 primes in 99.06289 seconds (last was 11381621)
Found 1000000 primes in 191.11001 seconds (last was 15485863)
genprime (Java)
Found 250000 primes in 8.12293 seconds (last was 3497861)
Found 500000 primes in 25.88073 seconds (last was 7368787)
Found 750000 primes in 41.94243 seconds (last was 11381621)
Found 1000000 primes in 64.42176 seconds (last was 15485863)
genprime (Objective-C)
Found 250000 primes in 1.99582 seconds (last was 3497861)
Found 500000 primes in 5.52849 seconds (last was 7368787)
Found 750000 primes in 10.01903 seconds (last was 11381621)
Found 1000000 primes in 15.39874 seconds (last was 15485863)
genprime (Perl)
Found 250000 primes in 57.16553 seconds (last was 3497861)
Found 500000 primes in 163.05147 seconds (last was 7368787)
Found 750000 primes in 296.21224 seconds (last was 11381621)
Found 1000000 primes in 493.05088 seconds (last was 15485863)
genprime (PHP)
Found 250000 primes in 44.62868 seconds (last was 3497861)
Found 500000 primes in 156.24447 seconds (last was 7368787)
Found 750000 primes in 218.98360 seconds (last was 11381621)
Found 1000000 primes in 339.03871 seconds (last was 15485863)
genprime (Python)
Found 250000 primes in 52.77145 seconds (last was 3497861)
Found 500000 primes in 149.61378 seconds (last was 7368787)
Found 750000 primes in 277.18452 seconds (last was 11381621)
Found 1000000 primes in 431.14573 seconds (last was 15485863)
genprime (Ruby)
Found 250000 primes in 133.67173 seconds (last was 3497861)
Found 500000 primes in 406.23774 seconds (last was 7368787)
Found 750000 primes in 695.72089 seconds (last was 11381621)
Found 1000000 primes in 1188.29837 seconds (last was 15485863)
Congratulations, Ruby! You now have the dubious honor of being the slowest scripting language at our disposal!
|
Page 1 of 5 | All times are UTC-05:00 |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |