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)