Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Speed of Split

by ysth (Canon)
on Nov 18, 2004 at 07:46 UTC ( [id://408709]=note: print w/replies, xml ) Need Help??


in reply to Speed of Split

I hesitate to mention this, but...

There is currently a minor optimization in split when assigning to a global array. You might give that a try:

local @data; foreach my $line (@lines) { @data = split /\s+/, $line; $time = shift @data; foreach my $datum (@data) { } }
untested, untimed.

Replies are listed 'Best First'.
Re^2: Speed of Split
by Lexicon (Chaplain) on Nov 18, 2004 at 09:53 UTC
    Odds are I'll go another route, but out of curiosity, does this speedup hold when assigning to something like @NAMESPACE::data?
      Yes, it does.
      $ perl -MO=Concise,-exec -e'@NAMESPACE::data = split / /, $x' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 </> pushre(/" "/ => @data) s/64 4 <#> gvsv[*x] s 5 <$> const[IV 0] s 6 <@> split[t4] vK 7 <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -e'@data = split / /, $x' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 </> pushre(/" "/ => @data) s/64 4 <#> gvsv[*x] s 5 <$> const[IV 0] s 6 <@> split[t4] vK 7 <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -e'my @data; @data = split / /, $x' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 <0> padav[@data:1,2] vM/LVINTRO 4 <;> nextstate(main 2 -e:1) v 5 <0> pushmark s 6 </> pushre(/" "/) s/64 7 <#> gvsv[*x] s 8 <$> const[IV 0] s 9 <@> split[t3] lK a <0> pushmark s b <0> padav[@data:1,2] lRM* c <2> aassign[t4] vKS d <@> leave[1 ref] vKP/REFC -e syntax OK

      See above that the array assignment is completely bypassed; instead the array is attached in a funny kind of way to the regex which is then passed to split, and split places the results directly into the array instead of returning them.

Re^2: Speed of Split
by itub (Priest) on Nov 19, 2004 at 01:18 UTC
    I also noticed that split in void context, although deprecated, is a little bit faster (or it was the last time I checked).

    split; # splits into @_

Log In?
Username:
Password:

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

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

    No recent polls found