Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to (Ovid): The monk recants by Ovid
in thread From one beginner to others . . . by greenhorn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found