I have nothing more to say on this topic. But I cannot refuse a reasonable request to publish my method of obtaining results.
Code follows. I ran the script on my MPC TransPort X3100, an obsolete laptop upgraded with a Pentium (R) M, with 2 Gb memory. Continued operation at top speed quickly overheats the chip, so I fixed the CPU frequency during these tests to 1.60 GHz. Interpreter version is 'v5.10.1 (*) built for i686-linux-thread-multi'. OS is Ubuntu 9.10, Linux 2.6.31-19-generic. I did my best to idle other tasks while benchmarking but I did not shut down X.
In the script, I bypass the ::XS enhancement with declarations of the form:
Readonly my $n_true => 1;
... instead of the correct:
Readonly::Scalar my $r_true => 1;
While I admit to some doubt as to why ::XS applies to one set of declarations and not the other; and have some small feeling that I would prefer to compare performance with ::XS loaded against that when it is completely not loaded; I'm confident that the usingNo_XS() routine reasonably reflects performance when ::XS is not available.
I noted earlier that you obtained the performance expected without ::XS even using the correct syntax; and therefore, you likely did not have Readonly::XS installed. You replied with, among other stuff, what looked very much like an effort to install it, whereupon your performance improved significantly, as expected. I don't understand why you're not pleased.
I cannot imagine personally fighting a pitched, cross-thread battle over a 2x difference in performance. I can imagine someone else doing so over a 40x difference, which results you showed previously (and which I preserve below). I do not, Sir, call you a liar. I merely fail to replicate your results.
You are /msg-ed.
#! /run/bin/perl
#~ use strict;
use warnings;
use Benchmark qw[ cmpthese ];
use constant {
C_TRUE => 1,
C_FALSE => 0,
C_VALUE => 12345,
};
use Readonly;
# Correct...
Readonly::Scalar my $r_true => 1;
Readonly::Scalar my $r_false => 0;
Readonly::Scalar my $r_value => 12345;
# Much slower...
Readonly my $n_true => 1;
Readonly my $n_false => 0;
Readonly my $n_value => 12345;
# My...
my $m_true = 1;
my $m_false = 0;
my $m_value = 12345;
# Package variables...
$p_true = 1;
$p_false = 0;
$p_value = 12345;
sub usingConstant {
for( 1 .. 1e6 ) {
if( C_TRUE ) {
my $sum = C_VALUE * C_VALUE;
}
elsif( C_FALSE ) {
;## Never called
}
}
}
sub usingReadonly {
for( 1 .. 1e6 ) {
if( $r_true ) {
my $sum = $r_value * $r_value;
}
elsif( $r_false ) {
;## Never called
}
}
}
sub usingNo_XS {
for( 1 .. 1e6 ) {
if( $n_true ) {
my $sum = $n_value * $n_value;
}
elsif( $n_false ) {
;## Never called
}
}
}
sub usingPackage {
for( 1 .. 1e6 ) {
if( $p_true ) {
my $sum = $p_value * $p_value;
}
elsif( $p_false ) {
;## Never called
}
}
}
sub usingMy {
for( 1 .. 1e6 ) {
if( $m_true ) {
my $sum = $m_value * $m_value;
}
elsif( $m_false ) {
;## Never called
}
}
}
sub usingLiterals {
for( 1 .. 1e6 ) {
if( 1 ) {
my $sum = 12345 * 12345;
}
if( 0 ) {
;## Never called
}
}
}
cmpthese -20, {
const => sub{ usingConstant() },
Readonly => sub{ usingReadonly() },
My => sub{ usingMy() },
literals => sub{ usingLiterals() },
package => sub{ usingPackage() },
No_XS => sub{ usingNo_XS() },
};
__END__
c:\test>ROvCONST.pl
s/iter Readonly const
Readonly 5.66 -- -98%
const 0.141 3931% --
(including No_XS; 1.60 GHz fixed)
No_XS 0.159/s -- -94% -94% -94% -96% -97%
My 2.76/s 1638% -- -1% -3% -36% -40%
Readonly 2.79/s 1661% 1% -- -2% -35% -39%
package 2.86/s 1700% 4% 2% -- -34% -38%
literals 4.33/s 2630% 57% 55% 52% -- -6%
const 4.60/s 2796% 67% 64% 61% 6% --
Rate No_XS Readonly My package literals const
No_XS 0.161/s -- -94% -94% -95% -96% -97%
Readonly 2.76/s 1619% -- -2% -8% -37% -42%
My 2.82/s 1659% 2% -- -6% -35% -40%
package 2.99/s 1764% 8% 6% -- -31% -37%
literals 4.36/s 2618% 58% 55% 46% -- -8%
const 4.73/s 2847% 71% 68% 58% 8% --
Rate No_XS Readonly My package literals const
No_XS 0.158/s -- -94% -94% -95% -96% -97%
Readonly 2.80/s 1666% -- -2% -6% -37% -41%
My 2.85/s 1697% 2% -- -5% -36% -40%
package 2.99/s 1785% 7% 5% -- -33% -37%
literals 4.47/s 2723% 60% 57% 50% -- -5%
const 4.73/s 2885% 69% 66% 58% 6% --
Note: Contents may change.
|