www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Help to improve speed

reply Jacob Carlborg <doobnet gmail.com> writes:
I have an application that maps numbers to words from a list of words 
written in Ruby. I've ported the application to D and it's terrible slow 
  and I don't know why. With a file of around 60 000 words and a file 
with around 25 000 numbers the Ruby application takes around 3 seconds 
and my D port takes around 209 seconds to finish. It's probably not well 
coded, I just tried to port it but over 200 seconds longer doesn't feel 
right.

I've attached the Ruby and D files.
Jun 09 2008
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Jacob Carlborg:
 I have an application that maps numbers to words from a list of words 
 written in Ruby. I've ported the application to D and it's terrible slow 
 and I don't know why.
Is the purpose of your program as this one, that I have written time ago? It may give you some ideas: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=57497 Note that ruby hashes may be faster than D ones (Python ones are much faster than D ones in all situations). Bye, bearophile
Jun 09 2008
parent Jacob Carlborg <doobnet gmail.com> writes:
bearophile wrote:
 Jacob Carlborg:
 I have an application that maps numbers to words from a list of words 
 written in Ruby. I've ported the application to D and it's terrible slow 
 and I don't know why.
Is the purpose of your program as this one, that I have written time ago? It may give you some ideas: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=57497 Note that ruby hashes may be faster than D ones (Python ones are much faster than D ones in all situations). Bye, bearophile
I think it is, thanks for the link. It's actually from this article: http://wwwipd.ira.uka.de/~prechelt/Biblio/jccpprtTR.pdf
Jun 09 2008
prev sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Jacob Carlborg wrote:
 I have an application that maps numbers to words from a list of words 
 written in Ruby. I've ported the application to D and it's terrible slow 
  and I don't know why. With a file of around 60 000 words and a file 
 with around 25 000 numbers the Ruby application takes around 3 seconds 
 and my D port takes around 209 seconds to finish. It's probably not well 
 coded, I just tried to port it but over 200 seconds longer doesn't feel 
 right.
Perhaps the D profiler can help: http://www.digitalmars.com/ctg/trace.html Also, using the D coverage analyzer can help: http://dobbscodetalk.com/index.php?option=com_myblog&show=Coverage-Analysis.html&Itemid=29
Jun 09 2008
parent reply Jacob Carlborg <doobnet gmail.com> writes:
Walter Bright wrote:
 Jacob Carlborg wrote:
 I have an application that maps numbers to words from a list of words 
 written in Ruby. I've ported the application to D and it's terrible 
 slow  and I don't know why. With a file of around 60 000 words and a 
 file with around 25 000 numbers the Ruby application takes around 3 
 seconds and my D port takes around 209 seconds to finish. It's 
 probably not well coded, I just tried to port it but over 200 seconds 
 longer doesn't feel right.
Perhaps the D profiler can help: http://www.digitalmars.com/ctg/trace.html Also, using the D coverage analyzer can help: http://dobbscodetalk.com/index.php?option=com_myblog&show=Coverage-Ana ysis.html&Itemid=29
Of course I should have mentioned that I use gdc osx so that switches won't work.
Jun 09 2008
next sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Jacob Carlborg wrote:
 Of course I should have mentioned that I use gdc osx so that switches 
 won't work.
Does gcov work with gdc?
Jun 09 2008
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Walter Bright wrote:
 Jacob Carlborg wrote:
 Of course I should have mentioned that I use gdc osx so that switches 
 won't work.
Does gcov work with gdc?
It does, and gdmd has a -cov wrapper argument for the required flags... http://www.digitalmars.com/d/archives/D/gnu/1563.html And yes, that was on Mac OS X too. --anders
Jun 10 2008
parent reply Jacob Carlborg <doobnet gmail.com> writes:
Anders F Björklund wrote:
 Walter Bright wrote:
 Jacob Carlborg wrote:
 Of course I should have mentioned that I use gdc osx so that switches 
 won't work.
Does gcov work with gdc?
It does, and gdmd has a -cov wrapper argument for the required flags... http://www.digitalmars.com/d/archives/D/gnu/1563.html And yes, that was on Mac OS X too. --anders
If I use the -cov switch or the switches in the link (-fprofile-arcs -ftest-coverage) I get this output, building with dsss: Undefined symbols: "___gcov_init", referenced from: global constructors keyed to 0__D10phonecode23mapHaain _phonecode2.o global constructors keyed to 0__D5tango2io11FileConduit11FileConduit5Style6__initZin tango.io.FileConduit.o global constructors keyed to 0__D5tango3sys6Common8SysError6__initZin tango.sys.Common.o global constructors keyed to 0__usr_bin_.._include_d_4.1.2_tango_stdc_stdint.d_9D3C70F3_1B27AB12in tango.stdc.stdint.o global constructors keyed to 0__D5tango4stdc5posix3sys4stat6stat_t6__initZin tango.stdc.posix.sys.stat.o global constructors keyed to 0__D5tango4stdc5errno5errnoFZiin tango.stdc.errno.o global constructors keyed to 0__D5tango2io8FilePath8FilePath6opCallFAaZC5tango2io8FilePath8FilePathin tango.io.FilePath.o global constructors keyed to 0__D5tango2io4Path2FS6__initZin tango.io.Path.o global constructors keyed to 0__D5tango4time4Time8TimeSpan6__initZin tango.time.Time.o global constructors keyed to 0_EOFin tango.stdc.stdio.o global constructors keyed to 0__D5tango2io13DeviceConduit13DeviceConduit5errorMFZvin tango.io.DeviceConduit.o global constructors keyed to 0__D5tango2io7Conduit7Conduit7isAliveMFZbin tango.io.Conduit.o global constructors keyed to 0__D5tango4text7convert3Utf8toStringFAuAaPkZAain tango.text.convert.Utf.o global constructors keyed to 0__D5tango2io6Stdout12_staticCtor1FZvin tango.io.Stdout.o global constructors keyed to 0__D5tango4text7convert5Float7__enum16__initZin tango.text.convert.Float.o global constructors keyed to 0__D5tango4text7convert7Integer5Style6__initZin tango.text.convert.Integer.o global constructors keyed to 0__D5tango2io7Console7Console6__initZin tango.io.Console.o global constructors keyed to 0__D5tango2io6Buffer6Buffer8overflowAain tango.io.Buffer.o global constructors keyed to 0__D5tango4text5Ascii7toLowerFAaAaZAain tango.text.Ascii.o global constructors keyed to 0__D5tango4text5Regex15RegExpException5_ctorMFAaZC5tango4text5Rege 15RegExpExceptionin tango.text.Regex.o global constructors keyed to 0__D5tango4math4Math1Eein tango.math.Math.o global constructors keyed to 0_HUGE_VALin tango.stdc.math.o global constructors keyed to 0__D5tango4math4IEEE9TANGO_NAN6__initZin tango.math.IEEE.o global constructors keyed to 0__D5tango4text4Util5jhashFPhkkZkin tango.text.Util.o global constructors keyed to 0__D5tango4time9StopWatch9StopWatch6__initZin tango.time.StopWatch.o "___gcov_merge_add", referenced from: ___mod_ref in _phonecode2.o ___mod_ref in tango.io.FileConduit.o __data 0 in tango.sys.Common.o __data 0 in tango.stdc.stdint.o __data 0 in tango.stdc.posix.sys.stat.o __data 0 in tango.stdc.errno.o ___mod_ref in tango.io.FilePath.o ___mod_ref in tango.io.Path.o __data 0 in tango.time.Time.o ___mod_ref in tango.stdc.stdio.o __D5tango2io13DeviceConduit13DeviceConduit7__ClassZ in tango.io.DeviceConduit.o __D5tango2io7Conduit12OutputFilter7__ClassZ in tango.io.Conduit.o __data 0 in tango.text.convert.Utf.o ___mod_ref in tango.io.Stdout.o __D5tango4text7convert5Float5pow10FkZe6PowersAe in tango.text.convert.Float.o __data 0 in tango.text.convert.Integer.o ___mod_ref in tango.io.Console.o __D5tango2io6Buffer6Buffer7__ClassZ in tango.io.Buffer.o __D5tango4text5Ascii7isearchFAaAaZi8_caseMapAa in tango.text.Ascii.o ___mod_ref in tango.text.Regex.o ___mod_ref in tango.math.Math.o __data 0 in tango.stdc.math.o ___mod_ref in tango.math.IEEE.o __data 0 in tango.text.Util.o ___mod_ref in tango.time.StopWatch.o ld: symbol(s) not found collect2: ld returned 1 exit status Error: Command failed, aborting. Command /usr/bin/rebuild returned with code 65280, aborting.
Jun 10 2008
parent Walter Bright <newshound1 digitalmars.com> writes:
Jacob Carlborg wrote:
 If I use the -cov switch or the switches in the link (-fprofile-arcs 
 -ftest-coverage) I get this output, building with dsss:
 
 Undefined symbols:
   "___gcov_init", referenced from:
       global constructors keyed to 0__D10phonecode23mapHaain _phonecode2.o
       global constructors keyed to 
I found that when I get those messages, using gcc (not ld) to link and passing it -fprofile-arcs and -ftest-coverage solves the problem. Clearly, gcc is adding some undocumented library to the ld command.
Jun 10 2008
prev sibling parent Lutger <lutger.blijdestin gmail.com> writes:
Jacob Carlborg wrote:

...

I tried running your program with the data sets from
http://page.mi.fu-berlin.de/prechelt/phonecode/ but I get the following
error: 
tango.core.Exception.ArrayBoundsException phonecode(199): Array index out of
bounds
Jun 10 2008