in reply to Eek! goto?

{ ($len or last) and $a+= $k[0]; ($len >= 2 or last) and $a+= $k[1] <<8; ($len >= 3 or last) and $a+= $k[2] <<16; ($len >= 4 or last) and $a+= $k[3] <<24; ($len >= 5 or last) and $b+= $k[4]; ($len >= 6 or last) and $b+= $k[5] <<8; ($len >= 7 or last) and $b+= $k[6] <<16; ($len >= 8 or last) and $b+= $k[7] <<24; ($len >= 9 or last) and $c+= $k[8] <<8; ($len >= 10 or last) and $c+= $k[9] <<16; ($len >= 11 or last) and $c+= $k[10] <<24; }
No goto. :-) (er, untested, might need more parens...)

update gah! what am I on. Reversed the test from <= to >=. Doh.

update 2 belg4mit pointed out that it needed a semicolon added, Thanks dude,

--- demerphq
my friends call me, usually because I'm late....

Replies are listed 'Best First'.
Re: Re: Eek! goto?
by BrowserUk (Patriarch) on Feb 12, 2003 at 01:37 UTC

    Updated: now I got pfaut's code to go.

    Neat! And faster (just) than the goto.

    However, with some adaption, pfaut's insight at Re: Eek! goto? allow's me to double the speed for this bit and save cycles earlier by avoiding spliting or unpacking the string to emulate the char[].

    Rate demerphq gotoit pfaut demerphq 916/s -- -1% -49% gotoit 923/s 1% -- -49% pfaut 1809/s 98% 96% --

    Benchmark and full results

    </code>

    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

      I thought up another approach last night after I had logged out. It still isn't faster than pfauts, but it is an interesting example of using code templates.
      Benchmark: running demerphq, gotoit, pfaut, template, each for at least 10 CPU seconds... demerphq: 11 wallclock secs (10.52 usr) @ 4809.81/s (n=50580) gotoit: 10 wallclock secs (10.31 usr) @ 5002.33/s (n=51584) pfaut: 10 wallclock secs (10.52 usr) @ 9265.21/s (n=97433) template: 11 wallclock secs (10.56 usr) @ 5934.77/s (n=62689) Rate demerphq gotoit template pfaut demerphq 4810/s -- -4% -19% -48% gotoit 5002/s 4% -- -16% -46% template 5935/s 23% 19% -- -36% pfaut 9265/s 93% 85% 56% --
      TMTOWTDI

      ;-)

      --- demerphq
      my friends call me, usually because I'm late....

        Mine may be fast but it makes some assumptions about the data. It assumes each value in @k is a byte value (between 0 and 255) and that $a, $b, and $c start out at 0. If the first is true but the second isn't, it might still work if the results of the unpack are stored in different variables and added to $a, $b, and $c. But I think BrowserUK said that this is part of some sort of encryption routine so it's quite possible the first assumption is wrong and thus the whole thing falls apart.

        --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';