Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: Triangle Numbers Revisited

by Limbic~Region (Chancellor)
on Oct 14, 2004 at 02:34 UTC ( #399080=note: print w/replies, xml ) Need Help??

in reply to Re: Triangle Numbers Revisited
in thread Triangle Numbers Revisited

The trouble with selecting a single number to benchmark from is that it may favor one method over the other. With this in mind, I created another rudimentary benchmark that shows the two methods are fairly equal:

First generate 5,000 random numbers between 1 .. 5_000_000

$ cat #!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] || 'targets.txt'; open (OUTPUT, '>', $file) or die "Unable to open $file for writing : $ +!"; print OUTPUT int rand 5_000_000, "\n" for 1 .. 5_000;

Next, I just modified our 2 scripts as follows:

my $file = $ARGV[0] || 'targets.txt'; open (INPUT, '<', $file) or die "Unable to open $file for reading : $! +"; while ( <INPUT> ) { chomp; get_three( $_ ); # used your sub/calling convention }

And finally, the results:

$ time ./ real 1m0.706s user 1m0.416s sys 0m0.080s $ time ./ real 1m0.791s user 1m0.326s sys 0m0.220s
I haven't spent any time thinking about optimizations, but if I come up with any tomorrow I will post it along with a "real" benchmark.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: Triangle Numbers Revisited
by FoxtrotUniform (Prior) on Oct 14, 2004 at 04:43 UTC
    The trouble with selecting a single number to benchmark from is that it may favor one method over the other.

    Good catch. Another problem I ran into was that the load on my test system was varying (lab machine, someone was logged in remotely doing a bunch of matlab foolery), so I ended up getting quite different "real" time results with the same input... which is probably what a casual reader would check.

    It would be interesting to know what kinds of inputs favour whose method, and (ideally) why.

    Yours in pedantry,
    F o x t r o t U n i f o r m

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://399080]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2017-09-22 01:08 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (255 votes). Check out past polls.