> -----Original Message-----
> From: John Doe [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, January 10, 2006 5:50 PM
> To: beginners@perl.org
> Subject: Re: Understanding Benchmark results
> 
> 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.

Thank you much for the replies gents! The information really helped.

I didn't even think about sorting while pulling from the MySQL database,
however and nonetheless, I also need an equal amount of data from flat
files in which I have to sort later anyhow :) I didn't bother mentioning
that as it was irrelevant at the time.

I'd really like to know an example where the Do-Nothing (TM) ST actually
Does-Something. In what type of situation would it be more useful than
sort? I must admit, I don't fully understand the map function to begin
with, so it makes it hard to understand exactly how it works, and/or
it's benefits. I pretty much copied the code out of my Perl ORM book
just to test, having the understanding that it is more efficient. I
believed that the process was 'expensive', simply because the amount of
data I was working with (which actually only turned out to take up about
36MB of memoryspace.

Tks again!

Steve






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


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