Hi all,

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.

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' 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?

---- 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%
a 79531/s 285%   --



-- 
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