Steve Bertrand am Dienstag, 10. Januar 2006 18.24:
> Hi all,

Hi Steve

> I've a project on the go, where I must compare a single field of more
> than 3 million database records, then sort them largest to smallest. The
> field will contain up to a 6 digit integer.

(I think you must have a reason not to sort the values while retrieving them 
from the database - or is it not a SQL db?)

> Just to ensure the most efficient possible run, I've been doing tests
> with benchmark.
>
> I'll post the relevant code, then the results. What I want to know is
> the cmpthese() results. I *think* that 'b' is much more efficient than
> 'a'. My assumption is that 'b' 

you mean: 'a'

> can perform 79531 operations per second, 
> where 'b' is only doing 20666. Am I looking at this right? Is the
> Schwartzian Transform really about 300% better than just plain sort?

No, about 300% more _slowly_, since 'a' is doing more per second than 'b'.

This seems also plausible from the fact that the schwarzian transformation in 
'b' does a comparison like 'a' does, but does additional work.

> ---- code snip (and yes -w and strict are in effect :) ----
>
> if ($benchTest) {
>
>         my $r1 = sub {
>                 my @unsorted = qw(3 4 9 88 24 1034 28);
>
>                 my @sorted = sort {$a <=> $b} @unsorted;
>         };
>
>         my $r2 = sub {
>                 my @unsorted = qw(3 4 9 88 24 1034 28);
>
>                 my @sorted =
>                 map $_->[0],
>                 sort { $a->[1] <=> $b->[1] }
>                 map [ $_, $_ ],
>                 @unsorted;
>         };
>
>         my $href = { 'a' => $r1, 'b' => $r2, };
>         my $result = timethese(-10, $href);
>         cmpthese($result);
>
> }
>
> ------------- results -----------
>
> Benchmark: running a, b, each for at least 10 CPU seconds...
>          a: 11 wallclock secs (10.59 usr +  0.01 sys = 10.60 CPU) @
> 79531.20/s (n=843155)
>          b: 11 wallclock secs (10.44 usr +  0.02 sys = 10.45 CPU) @
> 20665.69/s (n=216021)
>
>      Rate    b    a
> b 20666/s   -- -74%

read: b performs 74% compared with a.

> a 79531/s 285%   --

hth, 
joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to