in reply to Re: Re6: Anyone use "xor" in conditionals?
in thread Anyone use "xor" in conditionals?

I suspect that this will be roughly twice as fast as yours:

map { join ".", unpack "C*", $_ } sort map { pack "C*", split /\./, $_ } @ips;
and Benchmark says...
Rate slow faster tye slow 0.575/s -- -75% -83% faster 2.34/s 307% -- -32% tye 3.45/s 501% 48% --
Drat, only 50% faster. (: Probably because the S. Transform is specially optimized these days.

Full code in HTML comments at top of node so "download code" will fetch it for you.

                - tye

Replies are listed 'Best First'.
Re^9: [IP Sorting] Anyone use "xor" in conditionals? (faster)
by zengargoyle (Deacon) on Jul 16, 2003 at 00:22 UTC

    which is why i don't send in patches for this type of thing (slow but not broken). the actual fastest i've found is almost the most simple...

    use Socket qw( inet_aton inet_ntoa ); sub sort_sock { map { inet_ntoa($_) } sort map { inet_aton($_) } @_ }

    which give me:

           s/iter faster    tye   sock
    faster   2.06     --   -29%   -64%
    tye      1.46    41%     --   -49%
    sock    0.737   179%    98%     --
    

    can it get better? will locale settings mess with the sort? will Unicode bite me? i'm unsure.

      ++ zengargoyle!

      Using inet_aton and inet_ntoa for this is very elegant. I'll have to keep that trick in mind.


      Mike