in reply to Re: Fastest way to turn coordinate list into array
in thread Fastest way to turn coordinate list into array

Those results are different than what I would expect.

On perl, v5.10.0 built for i486-linux-gnu-thread-multi, I get what I'd expect:

Rate OP while_shift regex ike2 chromatic + ike1 OP 245/s -- -17% -28% -38% -48% + -50% while_shift 297/s 21% -- -13% -26% -36% + -39% regex 340/s 39% 15% -- -15% -27% + -31% ike2 398/s 63% 34% 17% -- -15% + -19% chromatic 467/s 91% 57% 37% 17% -- + -5% ike1 490/s 100% 65% 44% 23% 5% + --

On perl 5, version 12, subversion 0 (v5.12.0-RC1) built for i686-linux, I the same results.

Rate OP while_shift regex ike2 chromatic + ike1 OP 117/s -- -22% -28% -42% -52% + -54% while_shift 151/s 29% -- -7% -25% -38% + -41% regex 163/s 39% 8% -- -19% -33% + -36% ike2 202/s 72% 33% 24% -- -18% + -21% chromatic 244/s 109% 62% 50% 21% -- + -4% ike1 254/s 117% 68% 56% 26% 4% + --

The two extra tests are:

ike1 => sub { my @poly = map [ (split /,/, $_)[0, 1] ], split ' ', $coords; }, ike2 => sub { my @poly = map [ /([^,]*),([^,]*)/ ], split ' ', $coords; },

Replies are listed 'Best First'.
Re^3: Fastest way to turn coordinate list into array
by brancusi (Novice) on Apr 09, 2010 at 19:01 UTC

    Brilliant, thank you all for your speedy replies. FWIW the regex was simply hanging apache with real data at my end (some lists have 300K points) but the chromatic and ikegami solutions are definitely helping.

    It has highlighted that actually the real problem is algorithmic rather than performance of this section of code as the speed up, whilst beneficial, isn't the main problem. I can think of a way of whittling down the data to test in another part of the code so I'll try that out next. Again, many thanks - and ikegami's code will remain in as the winner so far. Roger
Re^3: Fastest way to turn coordinate list into array
by kennethk (Abbot) on Apr 09, 2010 at 18:59 UTC
    As I've pointed out in the update above, I reran and maintained ordering. I thought perhaps it was an 5.8/10 issue, but ran on my Linux box and got the following:

    Rate while_shift OP regex ike2 double_split chromatic + jwkrahn ike1 while_shift 15.0/s -- -11% -30% -40% -46% -51% + -54% -54% OP 16.8/s 12% -- -22% -33% -40% -45% + -48% -48% regex 21.5/s 43% 28% -- -14% -23% -29% + -34% -34% ike2 25.0/s 67% 49% 16% -- -10% -18% + -23% -23% double_split 27.9/s 86% 66% 30% 11% -- -8% + -14% -14% chromatic 30.4/s 102% 81% 41% 22% 9% -- + -6% -6% jwkrahn 32.4/s 116% 93% 50% 29% 16% 6% + -- -0% ike1 32.5/s 116% 93% 51% 30% 17% 7% + 0% -- This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi

    Anyone have an idea why my regex engine is so fast for ActiveState Perl 5.8.9?