Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Perl + binary

by zork42 (Monk)
on Oct 30, 2013 at 18:39 UTC ( #1060412=perlquestion: print w/ replies, xml ) Need Help??
zork42 has asked for the wisdom of the Perl Monks concerning the following question:


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

Comment on Perl + binary
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 sundialsvc4 (Monsignor) 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 Generoso (Vicar) 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.xs _<C:/citrusperl/site/lib/auto/DBI/DBI.dll CGITempFile:: CGI:: DBI:: _<C:/citrusperl/lib/CGI/

      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.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1060412]
Approved by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2014-08-29 18:35 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (286 votes), past polls