how to be faster than perl?

David Medlock noone at nowhere.com
Wed Jan 31 14:49:06 PST 2007


Boris Bukowski wrote:
> Hi,
> 
> currently I am testing D for log processing.
> My perl script is more than ten times faster than my D Prog.
> How can I get Lines faster from a File?
> 
> Boris 
> 
> ---snip---
> private import std.stream;
> private import std.stdio;
> private import std.string;
> 
> void main (char[][] args) {
>         int c;
>         Stream file = new BufferedFile(args[1]);
>         foreach(ulong n, char[] line; file) {
>                 if(std.regexp.find(line, "horizontal") > -1){
>                         c++;
>                 }
>         }
> 
>         writefln("%d", c);
> 
> }
> ---snip---
> 
> #!/usr/bin/perl
> 
> while($line=<>) {
>         if ($line=~/horizontal/) {
>                 $c++;
>         }
> }
> 
> print "$c\n";
> 
> ---snip---
> 

I am too lazy to look but does the regexp module cache any regexes 
passed to it?  Otherwise thats probably the major slowdown.

I am pretty sure all 'fixed' regexen in Perl are  pre-compiled into the 
AST so they aren't re-evaluated each time they are used.

I may be wrong though, I've only been using Perl about 7 months(and I 
despise it).

-DavidM


More information about the Digitalmars-d-learn mailing list