python 多线程 - Cpython, Jython 和 IronPython的多线程性能初步比较
2012-12-17 07:43
531 查看
(免责声明:本例并不一定典型,请勿上纲上线)
写了个简单的代码想比较下哪个解释器的多线程执行效率比较高……代码如下:
分别使用Cpython, Jython和IronPython解释执行,结果如下:
CPython:
Jython:
IronPython:
无语啊无语,除了C语言V5我还能说什么呢?
也许该试试python3.3?
然后把test函数的重复次数提升到50000000/5000000(十倍),结果:
CPython:
Jython:
(…………)
IronPython:
也许各个解释器的random实现方法不一致?我应该换个函数试试。
于是修改了test()中的内容,如下:
把重复次数设为5000000/500000,结果如下:
CPython:
Jython:
IronPython:
嗯……………………
写了个简单的代码想比较下哪个解释器的多线程执行效率比较高……代码如下:
''' Created on Dec 13, 2012 @author: festony ''' import random import threading from cj_lib import * def test(repeat): for i in range(repeat): random.random() @rec_proc_time('single thread') def run_test_1(): test(5000000) @rec_proc_time('multi thread - threading') def run_test_2(): ths = [] for i in range(10): ths.append(threading.Thread(target=test,args=(500000,))) for i in range(10): ths[i].start() for i in range(10): ths[i].join() run_test_1() run_test_2()
分别使用Cpython, Jython和IronPython解释执行,结果如下:
CPython:
Function {single thread} process time: 0.74492 sec(s) Function {multi thread - threading} process time: 1.34382 sec(s)
Jython:
Function {single thread} process time: 3.05519 sec(s) Function {multi thread - threading} process time: 1.37505 sec(s)
IronPython:
Function {single thread} process time: 1.48341 sec(s) Function {multi thread - threading} process time: 1.50126 sec(s)
无语啊无语,除了C语言V5我还能说什么呢?
也许该试试python3.3?
然后把test函数的重复次数提升到50000000/5000000(十倍),结果:
CPython:
Function {single thread} process time: 7.57535 sec(s) Function {multi thread - threading} process time: 12.9685 sec(s)
Jython:
java.lang.OutOfMemoryError: Java heap space at org.python.core.__builtin__.range(__builtin__.java:882)
(…………)
IronPython:
Function {single thread} process time: 14.9009 sec(s) Function {multi thread - threading} process time: 15.9274 sec(s)
也许各个解释器的random实现方法不一致?我应该换个函数试试。
于是修改了test()中的内容,如下:
ti = [5, 4, 9, 7, 12, 4, 7, 8, 13, 21] def test(repeat): for i in range(repeat): for j in range(10): x = j * ti[j]
把重复次数设为5000000/500000,结果如下:
CPython:
Function {single thread} process time: 6.19796 sec(s) Function {multi thread - threading} process time: 14.9035 sec(s)
Jython:
Function {single thread} process time: 21.2629 sec(s) Function {multi thread - threading} process time: 52.7627 sec(s)
IronPython:
Function {single thread} process time: 3.61389 sec(s) Function {multi thread - threading} process time: 1.49704 sec(s)
嗯……………………
相关文章推荐
- Python的各种解释器实现CPython | PyPy | Jython | IronPython等
- 互斥对象锁和临界区锁性能比较(临界区效率更高,互斥可用于多进程的多线程中)
- Python几种并发实现方案的性能比较
- python 中 五种字典(dict)的遍历方法,实验法比较性能。
- Python 多进程_进程池_多线程_线程池实现比较
- 再谈Python多线程--避免GIL对性能的影响
- Python的Set和List的性能比较 + 两者之间的转换
- Windows 7 64bit和Visual Studio 2010下的64位与32位程序配置,dll使用,与性能初步比较
- python2.7 与 go1.2简单性能比较
- Perl和Python的比较(主要是性能比较)
- python解释器(pypy,cpython,ironpython,jpython)
- HBase 高性能获取数据(多线程批量式解决办法) + MySQL和HBase性能测试比较
- Eclipse Pydev Python Jython IronPython Jpype 的关系
- python GIL 全局锁,多核cpu下的多线程性能究竟如何?
- Python的GIL是什么鬼,多线程性能究竟如何
- Python 的 GIL 是什么鬼,多线程性能究竟如何
- eventlet引发的学习-python:单线程、多线程在IO两方面的性能对比
- 精通 Oracle+Python,第 9 部分:Jython 和 IronPython — 在 Python 中使用 JDBC 和 ODP.NET
- 小测C#与C++、Python、IronPython求100000以内素数效率之比较
- Python:通过执行100万次打印来比较C和python的性能,以及用C和python结合来解决性能问题的方法