I thought I'd share a couple of test that I've done today with you.

(1) speed increases for inlining:

I was interested to know how much time was saved by inline constants.
The following script gives an answer:

#!perl -w
use strict;
use warnings;
use Benchmark qw( :hireswallclock timethese cmpthese );

sub a() {1001}; # will be inlined
sub b   {1001}; # won't be inlined

my $r = timethese( 100_000_000 , {
    a => sub {a},
    b => sub {b},
} );
cmpthese $r;

It takes a couple of minutes to run (w98SE, perl 5.8.7, 700MHz PII), and
when it works it gives results like below, although it also produces non-sensical results (with -ve times) on some runs.


C:\WINDOWS\Desktop>perl benchmark.pl
Benchmark: timing 100000000 iterations of a, b...
a: 19.4211 wallclock secs (19.39 usr +  0.00 sys = 19.39 CPU) @ 5157297
.58/s (n=100000000)
b: 145.188 wallclock secs (145.22 usr +  0.00 sys = 145.22 CPU) @ 68861
0.38/s (n=100000000)

       Rate    b    a
b  688610/s   -- -87%
a 5157298/s 649%   --

If this can be believed, then inlining is about 6-7 times faster than a
subroutine call (that's certainly possible).  Of course, the times
involved are minuscule, so you'd have to be doing a *lot* of references
to constants before this really made a difference, but interesting, none
the less.

(2) memory usage of Win32::GUI::Constants

This is, perhaps, more relevant, although I'm much less sure of what
interpretation I can make of the results.

I ran the following command lines from the cmd.exe shell on a w2k box.
I used sysinternals' 'Process Monitor' (verified by comparison with
numbers from the MS performance counters) to get the memory figures. The
varying and maximum figure were always within a few 10's of KBytes of
each other, so I am only quoting the max(peak) values.  All number in
KBytes.

Commands:
1= perl -Iblib/lib -e "sleep 100"
2= perl -Iblib/lib -e "use strict; use warnings; use warnings::register;
sleep 100"
3= perl -Iblib/lib -e "use Win32::GUI::Constants (); sleep 100"
4= perl -Iblib/lib -e "use Win32::GUI::Constants qw(:common); sleep 100"
5= perl -Iblib/lib -e "use Win32::GUI::Constants qw(:common -inline);
sleep 100"
6= perl -Iblib/lib -e "use Win32::GUI::Constants qw(:all); sleep 100"
7= perl -Iblib/lib -e "use Win32::GUI::Constants qw(:all -inline); sleep
100"

Test 2 is, I think, the best baseline figure to use, and differences
below are calculated from this figure.

Raw results:

Test          1      2      3      4      5      6      7

Perl 5.6.1
Private Bytes     884    1412    1420    3448    3468    3486    11668
Working Set    1596    1912    1964    2448    2436    3704     4688

Perl 5.8.7
Private Bytes     504     744     808    1220    1212    2824     2888
Working Set    1720    2088    2152    2580    2588    4200     4268

From this description (http://www.itwriting.com/dotnetmem.php) I think
that the private bytes is the number of interest.

Differences between baseline (test 2) and tests 3-7, for Private bytes:

Test        3      4      5      6      7
delta 5.6.1     8    2056    2056    2056    10256
delta 5.8.7    64     476     468    2080     2144

So, on the face of it Win32::GUI::Constants costs us no more than 2MB of
memory for all constants exported and compiled under perl 5.8.7, but
costs about 10MB for the same scenario on perl 5.6.1.  As I said, I'm
not sure how much you can really read into this, but make of it what you
want.

Regards,
Rob.

Reply via email to