开发者

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 开发者_JS百科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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜