in reply to Alternatives to split?

Really I just have a need for speed. When simply processing the file, getting some file pointers from tag matches and some seeking around the input file the process fly's. As soon as substr and especially split comes into play the process slows down.

Is this expected?

Replies are listed 'Best First'.
Re: Re: Alternatives to split?
by Skeeve (Parson) on Sep 03, 2003 at 11:02 UTC
    I really don't understand what you want to do.
    Do you just want to extract the part up to the first delimiter?
    try:
    my ($tag)= split(/|/,$_,2);
    my ($tag)= split(/\|/,$_,2);
    This won't split on all but just the first |.

    Update: Thanks to wirrwarr for correcting me

      You have to escape the "|", otherwise you'll split at each character.
      my ($tag)= split(/\|/,$_,2);
      daniel.
        Sorry all should have added..

        Have done the split on first field
        ($tag)=split (/\|/,$data,2);
        as well as substr and index stuff
        $tag=substr ($data,0,index($data,'\|',));
        I then benchmarked them
        Benchmark: timing 1000000 iterations of split, substr... split: 8 wallclock secs ( 6.93 usr + 0.00 sys = 6.93 CPU) @ 14 +4279.32/s(n=1000000) substr: 1 wallclock secs ( 1.54 usr + 0.00 sys = 1.54 CPU) @ 64 +8088.14/s(n=1000000)
        should split be slow compared to substr?
        Thinking about what i really want to know monks...
        Once i ahve the first field is there a quick way of spliting this field on first space then on an undersocre (if it exsits)?
        In my test file I have 5161033 lines, split slows down processing dramatically. When more substr are introduced processing slows down agian!