Ferrous Moon http://www.ferrousmoon.com:80/forums/ |
|
Programming Language Performance http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=1580 |
Page 5 of 5 |
Author: | Chase [Sun Dec 14, 2008 8:47 am ] |
Post subject: | Re: Programming Language Performance |
Quote: Quote: Ahh you didn't rerun the fortran version.
I dumped the FORTRAN version. The print formatting was impossible to get right, and the other natively compiled code tests basically show what FORTRAN would do anyway. |
Author: | eddieringle [Fri Apr 10, 2009 1:02 pm ] |
Post subject: | Re: Programming Language Performance |
Any chance you can test GenPrime using Ruby 1.9, Tycho? I'd like to see the differences. |
Author: | eddieringle [Tue Apr 14, 2009 6:32 pm ] |
Post subject: | Re: Programming Language Performance |
Nevermind, ran it on my laptop running Ubuntu 8.10. Versions: Code: ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
ruby1.9 -v
ruby 1.9.0 (2008-06-20 revision 17482) [i486-linux]
php -v
PHP 5.2.6-2ubuntu4.1 with Suhosin-Patch 0.9.6.2 (cli) (built: Feb 11 2009 20:38:24)
Results:ruby 1.8.7: Code: ruby genprime.rb 250000 1000000
Found 250000 primes in 219.86265 seconds (last was 3497861)
Found 500000 primes in 617.49590 seconds (last was 7368787)
Found 750000 primes in 1132.28696 seconds (last was 11381621)
Found 1000000 primes in 1750.21173 seconds (last was 15485863)
ruby 1.9.0:
Code: ruby1.9 genprime.rb 250000 1000000
Found 250000 primes in 45.06478 seconds (last was 3497861)
Found 500000 primes in 124.48929 seconds (last was 7368787)
Found 750000 primes in 227.51096 seconds (last was 11381621)
Found 1000000 primes in 350.35934 seconds (last was 15485863)
php 5.2.6:
Code: Found 250000 primes in 84.97550 seconds (last was 3497861)
Found 500000 primes in 237.42517 seconds (last was 7368787)
Found 750000 primes in 435.71111 seconds (last was 11381621)
Found 1000000 primes in 665.24334 seconds (last was 15485863)
These are all Ubuntu versions, NOT the latest releases from each language's developers. (Especially the PHP version, 5.2.6 is old)I'm surprised how much faster 1.9 is (and now I must switch to Ruby as my primary scripting language, due to a deal between ChaosR and I.) |
Author: | Tycho [Tue Apr 14, 2009 7:55 pm ] |
Post subject: | Re: Programming Language Performance |
Impressive. I wonder what the differences are between the 1.8.x and 1.9.x series which so drastically changed performance? |
Author: | ChaosR [Wed Apr 15, 2009 7:04 am ] |
Post subject: | Re: Programming Language Performance |
A bytecode interpreter instead of a syntax tree interpreter. |
Author: | Tycho [Wed Apr 15, 2009 2:22 pm ] |
Post subject: | Re: Programming Language Performance |
At least Ruby now can be considered competition for the others... |
Author: | eddieringle [Wed Nov 11, 2009 10:17 pm ] |
Post subject: | Re: Programming Language Performance |
With today's release of Go, I thought I would write a version of GenPrime for it, one because I wanted to see if it was really as speedy as it says and two to practice this new language. First, the C version as a comparison: Code: eddie@ganglion:~/dev/genprime$ ./genprime-c 250000 1000000
Found 250000 primes in 5.75923 seconds (last was 3497861)
Found 500000 primes in 16.15777 seconds (last was 7368787)
Found 750000 primes in 29.94442 seconds (last was 11381621)
Found 1000000 primes in 46.37428 seconds (last was 15485863)
Now for Go:
Code: eddie@ganglion:~/dev/genprime$ ./genprime-go 250000 1000000
Found 250000 primes in 4.253223 seconds (last was 3497861)
Found 500000 primes in 12.105688 seconds (last was 7368787)
Found 750000 primes in 22.779920 seconds (last was 11381621)
Found 1000000 primes in 34.426428 seconds (last was 15485863)
I compiled the Go version with the Plan 9 compiler (6g). Apparently there is a GCC port that is reported to produced more optimized code in some cases, so if anyone wants to test this code with the GCC port I'd be interested to see the results.I'll be committing my code to my GitHub fork of GenPrime. |
Author: | eddieringle [Wed Nov 11, 2009 10:21 pm ] |
Post subject: | Re: Programming Language Performance |
Assembly dump of isprime and genprime functions: Code: --- prog list "isprime" ---
0033 (genprime.go:46) TEXT isprime+0(SB),$40-16
0034 (genprime.go:46) MOVL x+0(FP),CX
0035 (genprime.go:15) JMP ,37
0036 (genprime.go:15) JMP ,42
0037 (genprime.go:15) CMPL CX,$2
0038 (genprime.go:15) JGE ,36
0039 (genprime.go:16) MOVL $0,.noname+8(FP)
0040 (genprime.go:16) RET ,
0041 (genprime.go:15) JMP ,42
0042 (genprime.go:18) JMP ,44
0043 (genprime.go:18) JMP ,49
0044 (genprime.go:18) CMPL CX,$4
0045 (genprime.go:18) JGE ,43
0046 (genprime.go:19) MOVL $1,.noname+8(FP)
0047 (genprime.go:19) RET ,
0048 (genprime.go:18) JMP ,49
0049 (genprime.go:21) JMP ,51
0050 (genprime.go:21) JMP ,56
0051 (genprime.go:21) CMPL CX,$5
0052 (genprime.go:21) JNE ,50
0053 (genprime.go:22) MOVL $1,.noname+8(FP)
0054 (genprime.go:22) RET ,
0055 (genprime.go:21) JMP ,56
0056 (genprime.go:24) JMP ,58
0057 (genprime.go:24) JMP ,71
0058 (genprime.go:24) MOVL CX,BX
0059 (genprime.go:24) MOVL CX,BP
0060 (genprime.go:24) MOVL CX,R8
0061 (genprime.go:24) SARL $31,R8
0062 (genprime.go:24) SUBL R8,BP
0063 (genprime.go:24) SARL $1,BP
0064 (genprime.go:24) IMULL $2,BP
0065 (genprime.go:24) SUBL BP,BX
0066 (genprime.go:24) CMPL BX,$0
0067 (genprime.go:24) JNE ,57
0068 (genprime.go:25) MOVL $0,.noname+8(FP)
0069 (genprime.go:25) RET ,
0070 (genprime.go:24) JMP ,71
0071 (genprime.go:27) JMP ,73
0072 (genprime.go:27) JMP ,88
0073 (genprime.go:27) MOVL CX,BX
0074 (genprime.go:27) MOVL CX,R8
0075 (genprime.go:27) MOVL $1717986919,AX
0076 (genprime.go:27) IMULL CX,
0077 (genprime.go:27) SARL $1,DX
0078 (genprime.go:27) SARL $31,R8
0079 (genprime.go:27) SUBL R8,DX
0080 (genprime.go:27) MOVL DX,BP
0081 (genprime.go:27) IMULL $5,BP
0082 (genprime.go:27) SUBL BP,BX
0083 (genprime.go:27) CMPL BX,$0
0084 (genprime.go:27) JNE ,72
0085 (genprime.go:28) MOVL $0,.noname+8(FP)
0086 (genprime.go:28) RET ,
0087 (genprime.go:27) JMP ,88
0088 (genprime.go:30) JMP ,90
0089 (genprime.go:30) JMP ,122
0090 (genprime.go:30) MOVL CX,BX
0091 (genprime.go:30) INCL ,BX
0092 (genprime.go:30) MOVL BX,R8
0093 (genprime.go:30) MOVL $715827883,AX
0094 (genprime.go:30) IMULL BX,
0095 (genprime.go:30) SARL $0,DX
0096 (genprime.go:30) SARL $31,R8
0097 (genprime.go:30) SUBL R8,DX
0098 (genprime.go:30) MOVL DX,BP
0099 (genprime.go:30) IMULL $6,BP
0100 (genprime.go:30) SUBL BP,BX
0101 (genprime.go:30) CMPL BX,$0
0102 (genprime.go:30) JEQ ,89
0103 (genprime.go:31) JMP ,105
0104 (genprime.go:31) JMP ,121
0105 (genprime.go:31) MOVL CX,BX
0106 (genprime.go:31) DECL ,BX
0107 (genprime.go:31) MOVL BX,R8
0108 (genprime.go:31) MOVL $715827883,AX
0109 (genprime.go:31) IMULL BX,
0110 (genprime.go:31) SARL $0,DX
0111 (genprime.go:31) SARL $31,R8
0112 (genprime.go:31) SUBL R8,DX
0113 (genprime.go:31) MOVL DX,BP
0114 (genprime.go:31) IMULL $6,BP
0115 (genprime.go:31) SUBL BP,BX
0116 (genprime.go:31) CMPL BX,$0
0117 (genprime.go:31) JEQ ,104
0118 (genprime.go:32) MOVL $0,.noname+8(FP)
0119 (genprime.go:32) RET ,
0120 (genprime.go:31) JMP ,121
0121 (genprime.go:30) JMP ,122
0122 (genprime.go:35) MOVL $0,match+-4(SP)
0123 (genprime.go:36) CVTSL2SD CX,X1
0124 (genprime.go:36) MOVSD X1,(SP)
0125 (genprime.go:36) CALL ,math.Sqrt+0(SB)
0126 (genprime.go:36) MOVL match+-4(SP),SI
0127 (genprime.go:36) MOVSD 8(SP),X0
0128 (genprime.go:36) MOVSD $(1.00000000000000000e+00),X1
0129 (genprime.go:36) ADDSD X1,X0
0130 (genprime.go:36) MOVSD X0,X5
0131 (genprime.go:37) MOVL $3,CX
0132 (genprime.go:37) JMP ,135
0133 (genprime.go:37) JMP ,150
0134 (genprime.go:37) ADDL $2,CX
0135 (genprime.go:37) CVTSL2SD CX,X1
0136 (genprime.go:37) MOVSD X1,X0
0137 (genprime.go:37) UCOMISD X1,X5
0138 (genprime.go:37) JLS ,133
0139 (genprime.go:38) JMP ,141
0140 (genprime.go:38) JMP ,149
0141 (genprime.go:38) MOVL x+0(FP),AX
0142 (genprime.go:38) CDQ ,
0143 (genprime.go:38) IDIVL CX,
0144 (genprime.go:38) CMPL DX,$0
0145 (genprime.go:38) JNE ,140
0146 (genprime.go:39) MOVL $1,SI
0147 (genprime.go:40) JMP ,133
0148 (genprime.go:38) JMP ,149
0149 (genprime.go:37) JMP ,134
0150 (genprime.go:43) JMP ,152
0151 (genprime.go:43) JMP ,157
0152 (genprime.go:43) CMPL SI,$1
0153 (genprime.go:43) JNE ,151
0154 (genprime.go:44) MOVL $0,.noname+8(FP)
0155 (genprime.go:44) RET ,
0156 (genprime.go:43) JMP ,157
0157 (genprime.go:46) MOVL $1,.noname+8(FP)
0158 (genprime.go:46) RET ,
0159 (genprime.go:46) CALL ,runtime.throwreturn+0(SB)
0160 (genprime.go:46) RET ,
--- prog list "genprime" ---
0161 (genprime.go:56) TEXT genprime+0(SB),$24-16
0162 (genprime.go:50) MOVL $1,AX
0163 (genprime.go:51) MOVL $0,CX
0164 (genprime.go:51) JMP ,167
0165 (genprime.go:51) JMP ,184
0166 (genprime.go:51) INCL ,AX
0167 (genprime.go:51) MOVL CX,count+-8(SP)
0168 (genprime.go:51) MOVL max+0(FP),BP
0169 (genprime.go:51) CMPL CX,BP
0170 (genprime.go:51) JGE ,165
0171 (genprime.go:52) JMP ,173
0172 (genprime.go:52) JMP ,183
0173 (genprime.go:52) MOVL AX,current+-4(SP)
0174 (genprime.go:52) MOVL AX,(SP)
0175 (genprime.go:52) CALL ,isprime+0(SB)
0176 (genprime.go:52) MOVL count+-8(SP),CX
0177 (genprime.go:52) MOVL current+-4(SP),AX
0178 (genprime.go:52) MOVL 8(SP),BX
0179 (genprime.go:52) CMPL BX,$1
0180 (genprime.go:52) JNE ,172
0181 (genprime.go:53) INCL ,CX
0182 (genprime.go:52) JMP ,183
0183 (genprime.go:51) JMP ,166
0184 (genprime.go:56) MOVL AX,BX
0185 (genprime.go:56) DECL ,BX
0186 (genprime.go:56) MOVL BX,.noname+8(FP)
0187 (genprime.go:56) RET ,
0188 (genprime.go:56) CALL ,runtime.throwreturn+0(SB)
0189 (genprime.go:56) RET ,
|
Author: | Tycho [Thu Nov 12, 2009 12:12 am ] |
Post subject: | Re: Programming Language Performance |
Ah, you used floating-point math, while the other implementations use integer math. Yes, you can get some speedups doing this, especially on Core 2 processors because a tight loop of integer divisions will always lose to a tight loop of floating-point divisions. You can do the same with the C version by using 'float' for prime_t and fmod() to replace the modulus operator. I'll work up some code which demonstrates this. |
Author: | eddieringle [Fri Nov 13, 2009 6:12 am ] |
Post subject: | Re: Programming Language Performance |
Quote: I'll work up some code which demonstrates this.
Well?
|
Author: | Tycho [Fri Nov 13, 2009 1:50 pm ] |
Post subject: | Re: Programming Language Performance |
Quote: Quote: I'll work up some code which demonstrates this.
Well? |
Author: | eddieringle [Thu Feb 18, 2010 3:15 pm ] |
Post subject: | Re: Programming Language Performance |
Quote: Quote: Quote: I'll work up some code which demonstrates this.
Well? |
Author: | Tycho [Sat Feb 20, 2010 4:16 am ] |
Post subject: | Re: Programming Language Performance |
No, I can do so tomorrow if you remind me somehow. Email would do. |
Author: | dodger [Sat Mar 13, 2010 9:51 am ] |
Post subject: | Re: Programming Language Performance |
That Java vs. Python results in your first post made me suspicous, cos Python is not that slow. Second thought was that its cos you ran it on a multi-core, maybe? Did Java utilize both cores? Cos Python does not support multi-threading, rather multi-processing. Oh, and whats about Delphi? Not sure if Delphi still counts, cos Ive heard it compiles with C now. Not sure. Long time ago that Ive used Delphi/Pascal. |
Author: | Tycho [Mon Mar 15, 2010 10:39 am ] |
Post subject: | Re: Programming Language Performance |
Quote: That Java vs. Python results in your first post made me suspicous, cos Python is not that slow. Second thought was that its cos you ran it on a multi-core, maybe? Did Java utilize both cores? Cos Python does not support multi-threading, rather multi-processing.
Python really is that slow. I have numerous examples to show it, too. If you or anyone else is interested, I can make these public. It's sad, too, because I'm a huge Python fan. It's a fantastic language, but the main implementation (CPython) is horrendously slow. Hopefully the Unladen Swallow guys finally get some optimization done and get their code merged into CPython.And no, multi-core couldn't have made a difference. We didn't really do anything in these tests that could be done in parallel, nor did we explicitly try to do so. Quote: Oh, and whats about Delphi? Not sure if Delphi still counts, cos Ive heard it compiles with C now. Not sure. Long time ago that Ive used Delphi/Pascal.
It's increasingly difficult to find Delphi or Pascal compilers. But if you want to contribute the code, go ahead. I just won't be able to test it.
|
Page 5 of 5 | All times are UTC-05:00 |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |