www.digitalmars.com         C & C++   DMDScript  

D - Bad performance of simple regular expression

reply MarcL <lohse mpimp-golm.mpg.de> writes:
hi everyone,

first of all i want to say that i'm not a professional programmer  - so the
problem i have might be
caused by my own  lack of experience. Nevertheless i want to describe it,
hoping that someone in this
group might be able to tell me what's wrong. I am a molecular biologist and i
often have to deal with
larger amounts of DNA and protein sequence data (which is in principle text). I
am mainly using Perl to
process these DNA files, and Perl generally performs very well (regular
expressions are actually the killer
tool for working with DNA sequences). Unfortunately not everything in Perl is a
fast as the regular
expressions and so i started trying to learn a language that can be compiled to
produce fast
executables : C++ - and went crazy because everything is so complicated. All
the ugly details that Perl
takes care of for the user have to be organized manually and that really gave
me the creeps. Then i
learned about D and it sounded like it the solution to my problem: A compilable
language that supports
associative arrays, garbage collection and (most importantly for me) regular
expressions! Great! I
experimented a bit and actually managed to write small working programlet
directly. I was delighted!
But now comes the reason why i write all this: Being enthusiastic about this
new nice language i started
to write a module that should implement basic functions for working with the
most common DNA
sequence file formats. To parse these files i planned to use regular
expressions. So far so good. When
testing my module with a small DNA file everything seemed OK -then i tried to
use it to parse a more
real world-sized DNA file (~155000 characters of DNA sequence plus about the
same amount of textual
information) and had to find out that a simple std.regexp.split call took about
59 seconds!!! I could not
believe it and wrote a little Perl script doing the same thing and it took less
than 1s!! What's wrong
here??? This can't really be true, can it? Is the implementation of regular
expressions in the phobos
library so bad or preliminary that it is so much less performant than the Perl
regex engine? It's actually
not usable for me like this (which is a sad think because i really like the
other features of D and would
like to use it). Am i making mistakes or do i simply have to wait for a better
version of phobos?

Any comments or suggestions would be great.

cheers
Feb 05 2007
parent Markus <schulz alpharesearch.de> writes:
If you look at this benchnark you will see two regex programs...
one is good and the other one is not.

http://shootout.alioth.debian.org/debian/benchmark.php?
test=regexdna&lang=all

Ratio Program & Logs Full CPU Time s Memory Use KB GZip Bytes



2.0 Python 7.33 23,592 326


2.8 Scheme MzScheme 10.04 182,448 819

3.0 Ruby 10.79 31,756 307

3.2 Java JDK -server 11.65 78,204 641
3.6 Scala 12.85 76,960 647

4.2 Lisp SBCL 15.06 305,796 709

5.0 JavaScript SpiderMonkey 18.14 180,884 349






1,208 Erlang 4,342.63 79,080 606
Apr 12 2007