how to be faster than perl?

mario pernici mario.pernici at mi.infn.it
Tue Jan 30 14:10:57 PST 2007


Boris Bukowski Wrote:

> 
> > // (untested code)
> > auto re = new RegExp("horizontal");
> > foreach (ulong n, char[] line; file) {
> >      if (re.find(line) > -1) {
> > // ...
> > -----
> > as the start of your foreach loop.
> > That should be faster.
> > 
> > I don't know how fast it'll be compared to Perl; I don't know anything
> > about the relative performance of D vs. Perl regexes. (In fact, I hardly
> > ever use regexes, and have never used Perl)
> 
> buko01 at dizit:~/d$ time ./lineio.pl access.log
> 1087
> 
> real    0m0.105s
> user    0m0.092s
> sys     0m0.012s
> buko01 at dizit:~/d$ time ./lineio2 access.log
> 1087
> 
> real    0m1.547s
> user    0m1.528s
> sys     0m0.020s
> 
> still 15 times slower :-(
> Perl strings/IO must be somehow black magic.
> Looks like I have to write my own lineReader.
> 
> Boris

Hello,
on my PC the D example is faster than the Perl one, with the data produced by
the Python script

f = open('data','w')
for j in range(1087):
  for i in range(100):
    f.write("%d\n" % i)
  f.write("horizontal\n")
  for i in range(100):
    f.write("%d\n" % i)
f.close()

the Perl example takes on my PC  0.068s,  the D example with auto re takes 0.068s.

Bye
   Mario


More information about the Digitalmars-d-learn mailing list