代码执行速度:IronPython 与 C#?
我试图从管理者的角度回答以下问题:如果我们用 IronPython 而不是 C# 编写应用程序,我们会遭受什么总体性能损失?
这个问题是针对那些可能已经进行了一些测试、基准测试或已经完成从 C# 到 IronPython 的迁移的人,以便量化惩罚。
Am trying to provide a response from a Managers perspective to the question: What overall performance penalty will we incur if we write the application in IronPython instead of C#?
This question is directed at those who might have already undertaken some testing, benchmarking or have completed a migration from C# to IronPython, in order to quantify the penalty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我创建了一个 C# 控制台应用程序(我不太擅长 C#),
它基本上使用异或密码来加密输入文件。
代码如下:
然后是等效的 Python 版本(我使用 SharpDevelop 4.0 构建可执行文件):
使用相同的纯文本 3,827 kb 文件测试它们的速度,
我得到这个:
C#:
73
IronPython 2.6 for .NET 4.0
所以我认为我们可以得出结论,IronPython 明显慢于 C#,
在这个特定的场景中。
我可能在这两个文件的代码中的某个地方犯了错误,所以请随时指出它们。我还在学习。
I created a C# console application (I'm not very good at C#),
which basically encrypts an input file using a xor cipher.
Code below:
and then the equivalent Python version, (I used SharpDevelop 4.0 to build an executable):
Testing their speeds with the same plaintext 3,827 kb file,
I get this:
C#:
73
IronPython 2.6 for .NET 4.0
So I think we can conclude that IronPython is significantly slower than C#,
in this particular scenario.
I might have made a mistake somewhere in my code in those two files, so feel free to point them out. I'm still learning.
IronPython 的性能总是比 C# 慢一点,因为它是解释性语言。您可以在 jcao219 答案 上看到它,尽管它是这不是一个好例子。
但开发速度实际上比性能更重要。对于优秀的 IronPython 开发人员来说,使用 IronPython 开发应用程序比使用 C# 更快。当然,当您(和您的同事)擅长 C# 时,您不应该考虑使用 IronPython 开发应用程序。
整体性能在很大程度上取决于代码的功能。在 IronPython 中加密不是一个好主意。电子表格应用程序是一个好主意 - 请参阅解析器一。他们考虑过将代码从 IronPython 转换为 C#,但他们还没有这样做,因为没有必要。当他们需要加速代码时,他们在 IronPython 本身中找到了一种方法来实现这一点。
IronPython performance will be always a little bit slower than C# because it is interpreted language. You can see it on jcao219 answer although it is not a good example.
But speed of development actually matters more that performance. Developing application in IronPython is faster than in C# for good IronPython developer. Of course, you should not consider developing application in IronPython when you (and your colleagues) are better in C#.
The overall performance heavily depends on what the code do. Encrypting in IronPython is not a good idea. Spreadsheet application is a good idea - see Resolver One. They thought about converting code from IronPython to C# but they have not done it yet because it is not necessary. When they needed to speed up the code, they have found a way in IronPython itself how to do it.
在单声道环境中,使用有限数量的基准测试,根据 计算机语言基准游戏网站。
In the mono environment, using a limited number of benchmarks, IronPython 2.6.1 looks to be 7 to 120 times slower than C# according to the Computer Language Benchmarks Game Site.
根据我的理解,两种语言都会被编译成 MSIL,因此理论上应用程序的性能应该相同或非常接近,但还有更多的人为因素。
我可以向你保证,我用 C# 编写的程序可能比用 iron-python 编写的相同程序快得多,不是因为 C# 更快,而是因为我更熟悉 C# 并且我知道要做出什么选择,所以如果你的团队如果您更熟悉 C#,那么如果您的应用程序是用 C# 编写的,或者反之亦然,那么您的应用程序将有更好的性能机会。
这只是个人理论,因此请持保留态度。
Based on my understanding both languages will be compiled into MSIL so theoretically the performance of the application should be identical or very close, but there is a lot more to it, the human factor.
I can assure you that a program I write in C# could be a lot faster that the same program in iron-python not because C# is faster but because I'm more familiar with C# and I know what choices to make, so if your team is more familiar with C# your application has a better chance at performance if it is written in C# or the other way around.
This is just a personal theory so take it with a grain of salt.