Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Counting the number of items returned by split without using a named array

by BrowserUk (Pope)
on May 03, 2006 at 14:08 UTC ( #547157=note: print w/replies, xml ) Need Help??


in reply to Re^2: Counting the number of items returned by split without using a named array
in thread Counting the number of items returned by split without using a named array

C:\test>p1 our $s = join ' ', 'aa'..'zz';; cmpthese -3, { split => q[ $_=$s; my $n = @{[ split ]}; ], regex => q[ $_=$s; my $n = () = /\S+/g; ] };; Rate regex split regex 546/s -- -50% split 1102/s 102% --

Assuming I didn't goof on the benchmark split appears to be quicker.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^3: Counting the number of items returned by split without using a named array
  • Download Code

Replies are listed 'Best First'.
Re^4: Counting the number of items returned by split without using a named array
by Anonymous Monk on May 03, 2006 at 15:16 UTC
    Strange
    perhaps it depends on the length of the input string?
    My attempt shows a different result
    You seem to be under windows - so just for comparison:
    $ cat a.pl; echo '-----------' ;echo;./a.pl #!/usr/local/bin/perl -w use Benchmark qw(:all) ; our $s = join ' ', 'aa'..'zz';; cmpthese( -3, { split => q[ $_=$s; my $n = @{[ split ]}; ], regex => q[ $_=$s; my $n = () = /\S+/g; ] }); ----------- Rate regex split regex 981/s -- -53% split 2098/s 114% --

    Hm, now where's the big diff to the other Bench?
    I.
      Hm, now where's the big diff to the other Bench?

      Try switching warnings on in your first benchmark. It will probably explain the difference :)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Ok, I see :)
        That could explain it *g*

        I.

      Argh... Link went wrong :( meant to link to the other benchmark above: http://www.perlmonks.org/?node_id=547169

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2021-01-19 03:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?