Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: (tye)Re: A better non-existant string...

by spaz (Pilgrim)
on Jan 23, 2001 at 06:42 UTC ( [id://53651]=note: print w/replies, xml ) Need Help??


in reply to (tye)Re: A better non-existant string...
in thread A better non-existant string...

I was going to disagree, but continue reading to see why I'm not. My code is below, have I done something wrong?
#!/usr/bin/perl use Benchmark; sub double { $teststring = ''; if( $teststring ne "" ) { return 1; } else { return 0; } } sub single { $teststring = ''; if( $teststring ne '' ) { return 1; } else { return 0; } } timethese( 1000000, { double => 'double( )', single => 'single( )' } );
Which gave these results on 3 consecutive trials
Benchmark: timing 1000000 iterations of double, single... double: 3 wallclock secs ( 2.14 usr + 0.00 sys = 2.14 CPU) single: 1 wallclock secs ( 1.86 usr + 0.00 sys = 1.86 CPU) Benchmark: timing 1000000 iterations of double, single... double: 1 wallclock secs ( 1.86 usr + 0.00 sys = 1.86 CPU) single: 2 wallclock secs ( 1.92 usr + 0.00 sys = 1.92 CPU) Benchmark: timing 1000000 iterations of double, single... double: 1 wallclock secs ( 1.89 usr + 0.00 sys = 1.89 CPU) single: 1 wallclock secs ( 1.86 usr + 0.00 sys = 1.86 CPU)
The way I understand the Benchmark module, system load at the time of benchmarking doesn't
influence the numbers. Is that statement correct? Does anybody know what's going on?

Replies are listed 'Best First'.
(tye)Re2: A better non-existant string...
by tye (Sage) on Jan 23, 2001 at 11:44 UTC

    It isn't the start-up time. It is probably an effect of the working set "settling in" or any number of other things that can affect benchmark numbers. In general, a 5% or less difference isn't something I would consider "real" as running it an hour later could certainly swing the answer that much. Here is the code I used:

    use Benchmark qw(cmpthese); my $str= "This is a test, " x 200; my $single= "'".$str."'"; my $double= '"'.$str.'"'; cmpthese( -3, { a_double => sub { eval $double }, b_single => sub { eval $single }, c_double => sub { eval $double }, d_single => sub { eval $single }, } );
    I don't have my original results (20% difference), but a re-run gave this:
    Rate a_double c_double b_single d_single a_double 4773/s -- -1% -23% -23% c_double 4830/s 1% -- -22% -22% b_single 6170/s 29% 28% -- -0% d_single 6172/s 29% 28% 0% --
            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://53651]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-26 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found