Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

(Ovid): The monk recants

by Ovid (Cardinal)
on Jul 16, 2000 at 04:08 UTC ( #22748=note: print w/replies, xml ) Need Help??


in reply to RE: RE: RE: RE: From one beginner to others . . .
in thread From one beginner to others . . .

D'oh! I optimized the split but not the regex :( That'll teach me to be careless. For honesty's sake:

timethese(1000000, { Regex => '$a=$1 if $myvar =~ /^[^,]+,([^,]+)/', Split1 => '$result = (split /,/, $myvar)[1]', Split2 => '$result = (split /,/, $myvar, 4)[1]', Split3 => '$result = (split /,/, $myvar, 3)[1]' }); Benchmark: timing 1000000 iterations of Regex, Split1, Split2, Split3. +.. Regex: 14 wallclock secs (14.12 usr + 0.00 sys = 14.12 CPU) Split1: 17 wallclock secs (16.54 usr + 0.00 sys = 16.54 CPU) Split2: 16 wallclock secs (16.75 usr + 0.00 sys = 16.75 CPU) Split3: 14 wallclock secs (13.02 usr + 0.00 sys = 13.02 CPU)
I'm going to cry myself to sleep tonight.

Curiously, though, it was the null assignments that appeared to be killing the efficiency ($a=$1, $b=$2, $c=$3, $d=$4) much more than the unoptimized regex. Hmmm....

Cheers,
Ovid

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://22748]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2022-12-05 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?