stas        2002/12/09 08:39:34

  Modified:    src/docs/2.0/devel config.cfg
               src/docs/2.0/devel/core apache_integration.pod
  Added:       src/docs/2.0/devel/performance speed_matters.pod
  Log:
  Throw in a beginning of: Which Coding Technique is Faster
  Owners are wanted!
  
  Revision  Changes    Path
  1.14      +1 -0      modperl-docs/src/docs/2.0/devel/config.cfg
  
  Index: config.cfg
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/docs/2.0/devel/config.cfg,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- config.cfg        9 Dec 2002 16:31:12 -0000       1.13
  +++ config.cfg        9 Dec 2002 16:39:33 -0000       1.14
  @@ -14,6 +14,7 @@
           core/apache_integration.pod
           core/coding_style.pod
           performance/size_matters.pod
  +        performance/speed_matters.pod
       )],
   
       group    => '3rd party modules Development with mod_perl 2.0',
  
  
  
  1.2       +1 -1      
modperl-docs/src/docs/2.0/devel/core/apache_integration.pod
  
  Index: apache_integration.pod
  ===================================================================
  RCS file: 
/home/cvs/modperl-docs/src/docs/2.0/devel/core/apache_integration.pod,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apache_integration.pod    9 Dec 2002 16:29:57 -0000       1.1
  +++ apache_integration.pod    9 Dec 2002 16:39:34 -0000       1.2
  @@ -1,6 +1,6 @@
   =head1 NAME
   
  -mod_perl internals: Apache 2.0 integration
  +mod_perl internals: Apache 2.0 Integration
   
   =head1 Description
   
  
  
  
  1.1                  
modperl-docs/src/docs/2.0/devel/performance/speed_matters.pod
  
  Index: speed_matters.pod
  ===================================================================
  =head1 NAME
  
  Which Coding Technique is Faster
  
  =head1 Description
  
  This document tries to show more efficient coding styles by
  benchmarking various styles.
  
  WARNING: This doc is under construction
  
  META: for now these are just unprocessed snippets from the mailing
  list. Please help me to make these into useful essays.
  
  =head1 backticks vs XS
  
  META: unprocessed yet.
  
  compare the difference of calling an
  xsub that does _nothing_ vs. a backticked program that does _nothing_.
  
    /* file:test.c */
    int main(int argc, char **argv, char **env)
    {
        return 1;
    }
  
    /* file:TickTest.xs */
    #include "EXTERN.h"
    #include "perl.h"
    #include "XSUB.h"
    
    MODULE = TickTest           PACKAGE = TickTest              
    
    void
    foo()
    
    CODE:
  
    # file:test.pl
    use blib;
    use TickTest ();
    
    use Benchmark;
    
    timethese(100_000, {
        backtick => sub { `./test` },
        xs => sub { TickTest::foo() },
    });
  
  Results:
  
    Benchmark: timing 100000 iterations of backtick, xs...
      backtick: 292 wallclock secs (18.68 usr 43.93 sys + 142.43 cusr 84.00 
csys = 289.04 CPU) @ 1597.19/s (n=100000)
            xs: -1 wallclock secs ( 0.25 usr +  0.00 sys =  0.25 CPU) @ 
400000.00/s (n=100000)
                (warning: too few iterations for a reliable count)
  
  
  =head1 sv_catpvn vs. fprintf
  
  META: unprocessed yet.
  
  and what i'm trying to say is that if both the xs code and external
  program are doing the same thing, xs will be heaps faster than backticking
  a program.  your xsub and external program are not doing the same thing.
  
  i'm guessing part of the difference in your code is due to fprintf having
  a pre-allocated buffer, whereas the SV's SvPVX has not been pre-allocated
  and gets realloc-ed each time you call sv_catpv.  have a look at the code
  below, fprintf is faster than sv_catpvn, but if the SvPVX is preallocated,
  sv_catpvn becomes faster than fprintf:
  
    timethese(1_000, {
        fprintf   => sub { TickTest::fprintf() },
        svcat     => sub { TickTest::svcat() },
        svcat_pre => sub { TickTest::svcat_pre() },
    });
    
    Benchmark: timing 1000 iterations of fprintf, svcat, svcat_pre...
       fprintf:  9 wallclock secs ( 8.72 usr +  0.00 sys =  8.72 CPU) @ 
114.68/s (n=1000)
         svcat: 13 wallclock secs (12.82 usr +  0.00 sys = 12.82 CPU) @ 78.00/s 
(n=1000)
     svcat_pre:  2 wallclock secs ( 2.75 usr +  0.00 sys =  2.75 CPU) @ 
363.64/s (n=1000)
    
    #include "EXTERN.h"
    #include "perl.h"
    #include "XSUB.h"
    
    static FILE *devnull;
    
    MODULE = TickTest           PACKAGE = TickTest              
    
    BOOT:
    devnull = fopen("/dev/null", "w");
    
    void
    fprintf()
    
        CODE:
        {
            int i;
            char buffer[8292];
    
            for (i=0; i<sizeof(buffer); i++) {
                fprintf(devnull, "a");
            }
        }
    
    void
    svcat()
    
        CODE:
        {
            int i;
            char buffer[8292];
            SV *sv = newSV(0);
    
            for (i=0; i<sizeof(buffer); i++) {
                sv_catpvn(sv, "a", 1);
            }
    
            SvREFCNT_dec(sv);
        }
    
    void
    svcat_pre()
    
        CODE:
        {
            int i;
            char buffer[8292];
            SV *sv = newSV(sizeof(buffer)+1);
    
            for (i=0; i<sizeof(buffer); i++) {
                sv_catpvn(sv, "a", 1);
            }
    
            SvREFCNT_dec(sv);
        }
  
  
  =head1 Maintainers
  
  Maintainer is the person(s) you should contact with updates,
  corrections and patches.
  
  Stas Bekman E<lt>stas (at) stason.orgE<gt>
  
  =head1 Authors
  
  =over
  
  =item *
  
  Stas Bekman E<lt>stas (at) stason.orgE<gt>
  
  =item * 
  
  Doug MacEachern E<lt>dougm (at) covalent.netE<gt>
  
  =back
  
  Only the major authors are listed above. For contributors see the
  Changes file.
  
  
  =cut
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to