Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Thought Experiment on Inline::C

by monkfan (Curate)
on Mar 19, 2005 at 14:04 UTC ( [id://440925]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Most Wises,

Let's suppose I have two codes, each does exactly the same thing. Except:

Code 1: Is written in pure C, both its *main* and subroutines.
Code 2: Is written in Perl for its *main* and with subroutines written in C, via Inline::C

My question is: will the performance/speed of Code 2 be (close) equal to Code 1?
Regards,
Edward

Replies are listed 'Best First'.
Re: Thought Experiment on Inline::C
by beauregard (Monk) on Mar 19, 2005 at 14:12 UTC
    Depends:
    1. perl will have a larger startup hit than the C code. If your application doesn't take long to run, that startup time may dwarf the runtime of the entire program. Inline::C will only compound this, at least the first time you run it.
    2. does main() do anything? i.e. is there a tight loop where it loads data and passes it to the subroutine? If so, the C code could be faster.
    3. is the program runtime bounded by something else, like reading/writing files? If so, the implementation language probably doesn't matter.
    4. does the program do something which perl does "naturally" (i.e. internally implemented in highly-tuned C code)? In that case, the perl version may be faster.
    As a rule of thumb, when you ask an experience programmer "which language is faster", the answer is probably going to be "whichever language is a more natural way to express the problem".

    c.

Re: Thought Experiment on Inline::C
by brian_d_foy (Abbot) on Mar 19, 2005 at 18:58 UTC

    You don't need a thought experiment because you can just try it. :)

    If the only reason you are using Perl is to provide a main() wrapper, then you are doing extra work that doesn't get you anything. That will be slower. If you want all of your subroutines to be in C, just use C. If your paramount (or only) concern is speed of execution, just use C.

    If you think Perl performance might be comparable though, try a Perl prototype and find out empirically. Good luck :)

    --
    brian d foy <bdfoy@cpan.org>
Re: Thought Experiment on Inline::C
by MrStretch (Sexton) on Mar 20, 2005 at 00:08 UTC
    Like they said. It all depends on what your doing. The execution of the code depends on what the code is doing. The easiest way to answer this question is to run them and see what difference there is.
Re: Thought Experiment on Inline::C
by blueberryCoffee (Scribe) on Mar 20, 2005 at 02:08 UTC
    Try it out both ways. Are you using C functions developed by someone else are you just don't like using C if you can help it?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://440925]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found