how to be faster than perl?
Boris Bukowski
boris.bukowski at lycos-europe.com
Wed Jan 31 03:23:12 PST 2007
mario pernici wrote:
> 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.
Hi,
with that generated data file D is faster, cause perl spends more time in
the loop.
I use a 20MB squid access log for testing.
looks like I have to write my own readline for this.
Boris
More information about the Digitalmars-d-learn
mailing list