You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matt Sergeant <ms...@startechgroup.co.uk> on 2001/09/26 17:45:16 UTC

Backticks as fast as XS

Robin Berjon thought I should post this as a heads-up to anyone thinking
what I thought: "XS or pure perl code will always be faster than backticks
or system() calls".

Wrong.

I spent some time converting some of our backtick programs to XS code here,
and the result was absolutely zero difference in performance.

I posted to c.l.p.moderated about this. The thread is here:
http://groups.google.com/groups?hl=en&frame=right&th=1cbfb00db194a925&seekm=
eb3031b9.0109100209.7c85168%40posting.google.com#link1

The OS was Linux (tested on kernel's 2.2 and 2.4). I think it's probably
fairly OS dependant, but I figure most people are on linux.

Matt.

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

Re: Backticks as fast as XS

Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 26 Sep 2001, Matt Sergeant wrote:

> Robin Berjon thought I should post this as a heads-up to anyone thinking
> what I thought: "XS or pure perl code will always be faster than backticks
> or system() calls".
> 
> Wrong.

matt your benchmark is severly flawed.  for starters, your xs and
external program do not do the same thing.  your xs has the overhead of
sv_catpv.  and who knows what else.  if you want proof that there
is overhead using backticks, compare the difference of calling an
xsub that does _nothing_ vs. a backticked program that does _nothing_.

test.c:
int main(int argc, char **argv, char **env)
{
    return 1;
}

TickTest.xs:

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

MODULE = TickTest		PACKAGE = TickTest		

void
foo()

    CODE:

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)