Steffen-

As always, I think benchmarks are important. As you've shown below, in
your case, the XS implementation certainly is faster. I think it all
depends on whether the speed of the system is bound by external
factors (like disk speed, speed of a network stream) or your CPU.

Certainly I've found for tight loops with lots of calculations, XS/C
is going to be faster. Why? Because it's compiled into machine code
and executed directly on the chip. On the other hand, Perl is compiled
into bytecode which is then executed by the Perl Virtual Machine.

However, this means you are also more prone to do things (in C/XS)
that will result in nasty problems like segfaults.

I see this debate as the same as "Perl vs C" or Language X vs Language
Y. Each language and each system is built for different purposes with
different advantages as well as limitations.

What this email reminds us all is of the importance of benchmarking
your code. Personally I use the one that gives tables comparing
things. It's useful to see just how much faster an XS module is, since
it does carry some additional risks (like nasty segfaults) over the
PurePerl equivalents.

Cheers,

Jonathan

On Wed, Nov 18, 2009 at 7:08 AM, O. STeffen BEYer <ost...@gmail.com> wrote:
> Dear Module Authors,
>
> recently in one of the Amsterdam Perl Mongers meetings the question came up
> how much faster actually the XS version of Date::Calc (Date::Calc::XS) was
> as compared to the Pure Perl version (Date::Calc::PP).
>
> Here is the answer (see attached script - you will need to have Date::Calc
> 6.3 and Date::Calc::XS 6.2 installed to run this script successfully):
>
> FreeBSD 7.2.-stable:
>
> $ perl benchmark.pl
> Running under Date::Calc::PP version 6.3
> timethis 5000: 17.3147 wallclock secs (17.24 usr +  0.06 sys = 17.30 CPU) @
> 288.94/s (n=5000)
> Running under Date::Calc::XS version 6.2
> timethis 5000: 1.02551 wallclock secs ( 0.97 usr +  0.06 sys =  1.03 CPU) @
> 4848.48/s (n=5000)
>
> Windows XP SP3:
>
> Running under Date::Calc::PP version 6.3
> timethis 5000: 17.1034 wallclock secs (16.86 usr +  0.00 sys = 16.86 CPU) @
> 296.58/s (n=5000)
> Running under Date::Calc::XS version 6.2
> timethis 5000: 1.3329 wallclock secs ( 1.28 usr +  0.00 sys =  1.28 CPU) @
> 3900.16/s (n=5000)
>
> Another (faster) Windows XP SP3 machine:
>
> Running under Date::Calc::PP version 6.3
> timethis 10000: 20.5605 wallclock secs (20.55 usr +  0.00 sys = 20.55 CPU) @
> 486.69/s (n=10000)
> Running under Date::Calc::XS version 6.2
> timethis 10000: 1.44224 wallclock secs ( 1.42 usr +  0.00 sys =  1.42 CPU) @
> 7032.35/s (n=10000)
>
> One can see from these results that the XS version quite consistently runs
> approximately about 15 times faster than the PP version.
>
> The test script benchmarks a function which calls all functions in
> Date::Calc once, each.
>
> Other similar results from XS/PP pairs of modules would be interesting -
> maybe not for any practical purposes, but just for the fun of it
> (or maybe to give deciders convincing arguments to upgrade to an XS version
> or not).
>
> Cheers,
> Steffen
>

Reply via email to