ocehb: (Default)
ocehb ([personal profile] ocehb) wrote2006-03-02 09:36 am
Entry tags:

Perl newbie

нашел в одном месте задачку на упрощение: мой вариант: sort { (keys %$a)[0] <=> (keys %$b)[0] }. Benchmark на

foreach (1..1024) {
        push @ary,{ int (rand 102400)%$ARGV[0] => "a" . int (rand (1024)) };
}
...
timethese (102400,{ 'a1' => sub { a1 (@ary); },'a2' => sub { a2 (@ary); } })

такой:
Benchmark: timing 102400 iterations of a1, a2...
        a1: 520 wallclock secs (489.74 usr +  0.34 sys = 490.08 CPU) @ 208.95/s (n=102400)
        a2:  1 wallclock secs ( 0.92 usr +  0.00 sys =  0.92 CPU) @ 111304.35/s (n=102400)
Real: 521.32s User: 490.93s System: 0.36s Percent: 94%% Cmd: perl a.pl 1024 102400
А у вас? :)

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org