简体   繁体   English

哪个有更好的性能:通过系统调用从C ++执行Perl脚本,还是调用DLL文件?

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

I am new to C++ coding. 我是C ++编码的新手。

I wanted to execute a Perl script (that controls an equipment) inside a C++ Visual Studio Win32 application. 我想在C ++ Visual Studio Win32应用程序中执行Perl脚本(控制设备)。 I was wondering what would be the most optimized approach in this regards? 我想知道在这方面最优化的方法是什么?

  1. Call system function and execute that particular Perl file. 调用系统函数并执行该特定的Perl文件。
  2. Create some kind of DLL and call that DLL inside my C++ code. 创建某种DLL并在我的C ++代码中调用该DLL。

Option 2 I have never used, but I am willing to learn and implement if that's the best way. 选项2我从未使用过,但如果这是最好的方法,我愿意学习和实施。

I believe the "most optimized" approach is to embed Perl in your application. 我相信“最优化”的方法是将Perl嵌入到您的应用程序中。

Your second option is not really feasible, AFAIK. 你的第二种选择并不可行,AFAIK。 Since Perl is not compiled, your only other option would be to invoke the interpreter (eg through a system() or exec() -family call), as per your first option. 由于Perl未编译,因此根据您的第一个选项,您唯一的另一个选择是调用解释器(例如通过system()exec()家庭调用)。

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. 我同意Oystein的说法,你不太可能找到一种将perl脚本编译成共享库的好方法。

However, spawning perl from your C++ program isn't the only other option. 但是,从C ++程序中生成perl并不是唯一的选择。 You could also pipe data between the two programs, use a socket to pass data between them, and other IPC methods. 您还可以在两个程序之间管道数据,使用套接字在它们之间传递数据,以及其他IPC方法。

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). 在我的备份工具中,我曾尝试调用system("perl script.pl") ,但它在Windows上运行速度非常慢(即使测试基准测试中的script.pl没有做任何事情,每秒20-30次调用左右)。 On Linux it was much, much quicker. Linux上它更快,更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从C语言中用C语言开发的DLL调用函数 - Calling a function from a DLL which is developed in C++ from C 哪个更好 - 从 c 程序调用 c++ 库? - Which one is the better - calling c++ library from c program? 从我的c ++应用程序调用c#dll(解析XML文件)以将数组/列表返回给c ++ - Calling c# dll (which parses XML file) from my c++ application to return array / list to c++ 当我将我的c ++ DLL(我从c#调用)重建为/ CLR(原始本机)时,性能下降了一半 - When I rebuild my c++ DLL (which I call from c#) into /CLR (originally native) the performance drops in half C#代码未调用应该调用的c ++ dll函数(具有类指针作为参数),我不应该更改c ++代码 - C# code is not calling the c++ dll function (which has a class pointer as parameter) that it is supposed to call and i should not change the c++ code 从 C++ Z06416233FE5EC4C5933122E4AB248AF1 调用 Go dll - Calling a Go dll from a C++ dll 在C ++文件中调用dll - call dll in a c++ file 从C#调用非托管.dll的性能 - Performance of Calling Unmanaged .dll from C# WCF服务调用具有复杂数据类型的非托管C ++ DLL - WCF Service calling a unmanaged c++ dll which has complex datatypes 哪个更好; 用于基于 c/c++ 的 windows 应用程序的 dll 或 jar - Which is better; a dll or a jar for c/c++ based windows application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM