#!/usr/bin/perl use strict; use warnings; use Benchmark qw/cmpthese/; print "== Single subroutine argument ==\n"; sub b1_shift { my $x = shift; $x . ''; } sub b1_list { my ($x) = @_; $x . ''; } sub b1_direct { $_[0] . ''; } cmpthese( -5, { 'shift' => sub { b1_shift ('X' x rand 5000) }, 'list assignment' => sub { b1_list ('X' x rand 5000) }, 'direct' => sub { b1_direct('X' x rand 5000) } }); print "== Two subroutine arguments ==\n"; sub b2_shift { my $x = shift; my $y = shift; $x . $y; } sub b2_list { my ($x, $y) = @_; $x . $y; } sub b2_direct { $_[0] . $_[1]; } cmpthese( -5, { 'shift' => sub { b2_shift ('X' x rand 5000, 'Y' x rand 5 +000) }, 'list assignment' => sub { b2_list ('X' x rand 5000, 'Y' x rand 5 +000) }, 'direct' => sub { b2_direct('X' x rand 5000, 'Y' x rand 5 +000) } }); __END__ == Single subroutine argument == Benchmark: running direct, list assignment, shift, each for at least 5 + CPU seconds... direct: 5 wallclock secs ( 5.10 usr + 0.02 sys = 5.12 CPU) @ 11 +0247.85/s (n=564469) list assignment: 5 wallclock secs ( 5.14 usr + 0.03 sys = 5.17 CPU) + @ 89861.90/s (n=464586) shift: 6 wallclock secs ( 5.72 usr + 0.03 sys = 5.75 CPU) @ 70 +120.00/s (n=403190) Rate shift list assignment dire +ct shift 70120/s -- -22% -3 +6% list assignment 89862/s 28% -- -1 +8% direct 110248/s 57% 23% +-- == Two subroutine arguments == Benchmark: running direct, list assignment, shift, each for at least 5 + CPU seconds... direct: 5 wallclock secs ( 5.46 usr + 0.00 sys = 5.46 CPU) @ 57 +434.25/s (n=313591) list assignment: 6 wallclock secs ( 5.30 usr + 0.02 sys = 5.32 CPU) + @ 46535.53/s (n=247569) shift: 6 wallclock secs ( 5.00 usr + 0.01 sys = 5.01 CPU) @ 42 +526.95/s (n=213060) Rate shift list assignment direc +t shift 42527/s -- -9% -26 +% list assignment 46536/s 9% -- -19 +% direct 57434/s 35% 23% - +-

2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$


In reply to Re: XML::SAX::PurePerl Performance by Juerd
in thread XML::SAX::PurePerl Performance by Matts

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.