user2829
user2829

Reputation: 461

Which has better performance: executing a Perl script from C++ via system call, or calling a DLL file?

I am new to C++ coding.

I wanted to execute a Perl script (that controls an equipment) inside a C++ Visual Studio Win32 application. I was wondering what would be the most optimized approach in this regards?

  1. Call system function and execute that particular Perl file.
  2. Create some kind of DLL and call that DLL inside my C++ code.

Option 2 I have never used, but I am willing to learn and implement if that's the best way.

Upvotes: 1

Views: 1246

Answers (3)

Lasse
Lasse

Reputation: 1

In my backup tool I once tried invoking system("perl script.pl"), but it ran very slow on Windows (20-30 calls per second or so even though script.pl in a test benchmark did nothing). On Linux it was much, much quicker.

Upvotes: -1

user1481860
user1481860

Reputation:

I believe the "most optimized" approach is to embed Perl in your application.

Your second option is not really feasible, AFAIK. Since Perl is not compiled, your only other option would be to invoke the interpreter (e.g. through a system() or exec()-family call), as per your first option.

Now, there is quite a difference between embedding an interpreter in your code, and writing one line of code to call an external program, so you have to consider exactly how much optimization you need. The performance difference might even be minimal, so I strongly suggest that you try the easy way first, measuring your success.

Upvotes: 7

Ben Voigt
Ben Voigt

Reputation: 283733

I agree with Oystein that you're not likely to find a good way to compile the perl script into a shared library.

However, spawning perl from your C++ program isn't the only other option. You could also pipe data between the two programs, use a socket to pass data between them, and other IPC methods.

Upvotes: 4

Related Questions