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

Sorting a list of IP addresses (aka Why I hate Big O)

by jeffa (Bishop)
on Aug 03, 2000 at 00:15 UTC ( #25833=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
    #naive: O(N*logN)
    my @sorted = sort {
        pack('C4' => $b =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/)
    } @unsorted;
  2. or download this
    Benchmark: timing 5000 iterations of naive, packed...
         naive: 11 wallclock secs ( 9.91 usr +  0.32 sys = 10.23 CPU)
        packed:  8 wallclock secs ( 7.95 usr +  0.08 sys =  8.03 CPU)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://25833]
Approved by root
[LanX]: yep
[LanX]: 1234567890 1234567890 1234567890
[LanX]: so inserting own whitespace helps, ie. a JS warning on submit could help preventing problems
[LanX]:  last hour of cb doesn't break

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-07-24 11:00 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (350 votes). Check out past polls.