Search code examples
performanceperlsystem

calling perl script with system VS implementing package


Let me start with giving an example of what I'm dealing with first:

I often call existed Perl scripts from previous engineers to process some data, and then proceed further with my script. I either use system or back-ticks to call other people scripts within my script.

Now, I'm wondering if I rewrite those scripts as packages and use require or use to include those packages in my script, will it increase the processing speed? How big of a difference would it be?


Solution

  • Benefits:

    • It would save the time taken to load the shell, load perl, compile the script and the module it uses. That's a couple of seconds minimum, but it could be much larger.
    • If you had to serialize data to pass to the child, you also save the time taken to serialize and deserialize the data.
    • It would allow more flexible interfaces.
    • It would make error handling easier and more flexible.

    Downsides:

    • Since everything is now in the same process, the child can have a much larger effect on the parent. e.g. A crash in the child will take down the parent.