http://www.perlmonks.org?node_id=1060412

zork42 has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I hope these aren't dumb questions:
  1. Is there a quick & easy way to check if a module is pure-Perl, or is Perl+binary for both CPAN and core modules?
  2. Do Perl+binary modules always use XS or are there other methods?
  3. I need to code a function in C for the speed, is it possible to somehow include the C source in the perl source and get the C compiled? Or do I have to use XS and xsubpp?
  4. I realise this is a bit like asking how long a piece of string is (*), but roughly how much faster will a C version of a perl sub be?
Many thanks.

(*) it's twice as long as the distance from the middle to an end ;-)

UPDATE: I forgot to say I'm running ActivePerl on Windows

Replies are listed 'Best First'.
Re: Perl + binary
by sundialsvc4 (Abbot) on Oct 30, 2013 at 19:05 UTC

    The “how much faster” question depends altogether on just what the script is doing.   Some modules, like JSON::XS, do typically run “noticeably faster,” but there are “pure Perl” implementations, too.   Quite often, binary code is used to interface with an existing, known library, as in XML::LibXML, which is “Perl glue” for the standard library libxml2.

Re: Perl + binary
by Anonymous Monk on Oct 30, 2013 at 18:42 UTC

        The big advantage of Inline::C is in my opinion that it is relatively easy to move from an Inline::C implementation to a full XS implementation, mostly by copying the right files at the right stage. Inline::C basically automates building an XS file for you.

        This enables you to distribute the compiled file across machines that don't have a C compiler installed and shouldn't have the facility to compile C code. C::TinyCompiler (of course) provides the facility to compile C code on the fly.

        According to its documentation, C::TinyCompiler only works for x86 and ARM processors. Whether that includes x64, I don't know, but if you need to run your code on PPC or other architectures, the Inline::C approach will use the tools used to build Perl for the target architecture and thus is sure to be compatible with the architecture.

Re: Perl + binary
by Generoso (Prior) on Oct 30, 2013 at 22:06 UTC

    There are no dumb questions, only dummies, that do not ask.

      Is there a quick & easy way to check if a module is pure-Perl, or is Perl+binary for both CPAN and core modules?

      No. Well kinda. Sure-fire-way is to look at he source.

      Cheap tricks

      $ perl -MCGI -MDBI -le " print for grep /CGI|DBI/, keys %:: " _<DBI.c _<DBI.pm _<DBI.xs _<C:/citrusperl/site/lib/auto/DBI/DBI.dll CGITempFile:: CGI:: DBI:: _<C:/citrusperl/lib/CGI/Util.pm

      so DBI.dll/DBI.xs/DBI.c means DBI is binary, lack of .c/.xs/.dll/.so means CGI is pure-perl

Re: Perl + binary
by zork42 (Monk) on Oct 31, 2013 at 03:08 UTC
      Yes. Install the Mingw package and dmake package using PPM.

      The other choice install a Visual Studio or the GUI-less Platform/Windows SDKs for MS C compilers and not GCC.
        Thanks!

        Is it hard to configure the correct build/compile options?