基准 [英] benchmark

查看:80
本文介绍了基准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道一个基准测试并不是很有意义但是看起来仍然令人失望,因为它是测试中最慢的语言之一:

< a rel =nofollowhref =http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/\"target =_ blank> http: //blog.dhananjaynene.com/2008/0...-jruby-groovy/

解决方案

Jack写道:


我知道一个基准测试并不意味着很多但是看起来仍然令人失望地认为这是测试中最慢的语言之一:

http://blog.dhananjaynene.com/2008/0...-jruby-groovy/


-
http://mail.python.org/mailman/listinfo / python-list



需要注意的事项,python版本是

其余部分长度的一半;>


8月7日凌晨2:05,杰克 < nos ... @ invalid.comwrote:


我知道一个基准测试并不意味着很多,但看到
仍然令人失望
Python是测试中最慢的语言之一:

http://blog.dhananjaynene.com/2008/0...rison-c-java-p ...


Python代码不好,它包含range()而不是xrange,

大循环在主代码而不是函数内部,使用==

无,等等。这个人可以尝试这个(和Psyco一起),我已经改变了很多

一点,代码基本相同:

导入时间,psyco

来自psyco.classes import __metaclass__


class人物:

def __init __(self,count):

self.count = count

self.prev =无

self.next =无

def shout(self ,喊,死的):

if shout< deadif:

返回喊+ 1

self.prev.next = self.next

self.next.prev = self.prev

返回1


类链:

def __init __(自我,大小):

self.first =无

last =无
$ x $ b for x in xrange(size):

current = Person(i)

如果self.first为None:

self.first = current

如果last不是None:

last.next = current

current.prev = last

last = current

self.first.prev = last

last.next = self .first

def kill(self,nth):

current = self.first

shout = 1

而current.next!=当前:

shout = current.shout(shout,nth)

current = current.next

self.first =当前

返回当前

def main():

ITER = 100000

start = time.time( )
$ x $ b for x in xrange(ITER):

chain = Chain(40)

chain.kill(3) )

end = time.time()

print''每次迭代的时间=%s微秒''%((结束 - 开始)*

1000000 / ITER)


psyco.full()

main()


us = microseconds

在我的电脑上(看起来与他的相似)这个版本需要大约38.9

us / iter而不是189.


在我的电脑上,Java版本需要1.17美元,而C ++版本(带有

MinGW 4.2.1)需要9.8美元。

原始D翻译需要14.34 us,而清理(​​使用

结构,没有getter / setter)需要4.67 us。

我不知道为什么我的C ++这么慢(做同样的事情)到C的东西
++版本并没有太多改变其运行时间。


再见,

熊宝宝


Jack写道:


我知道一个基准并不意味着什么,但它仍然令人失望看看

Python作为测试中最慢的语言之一:

http://blog.dhananjaynene.com/2008/0...-jruby-groovy/



只需忽略它。如果代码从一开始就是为Python而设计的,那么
会表现得更好。


目前它看起来像语法改编的Java代码我。


Stefan


I know one benchmark doesn''t mean much but it''s still disappointing to see
Python as one of the slowest languages in the test:

http://blog.dhananjaynene.com/2008/0...-jruby-groovy/

解决方案

Jack wrote:

I know one benchmark doesn''t mean much but it''s still disappointing to see
Python as one of the slowest languages in the test:

http://blog.dhananjaynene.com/2008/0...-jruby-groovy/
--
http://mail.python.org/mailman/listinfo/python-list

Something to note though, The python version is ~ half the length of the
rest of them ;->


On Aug 7, 2:05 am, "Jack" <nos...@invalid.comwrote:

I know one benchmark doesn''t mean much but it''s still disappointing to see
Python as one of the slowest languages in the test:

http://blog.dhananjaynene.com/2008/0...rison-c-java-p...

That Python code is bad, it contains range() instead of xrange, the
big loop is in the main code instead of inside a function, uses ==
None, etc. That person can try this (with Psyco), I have changed very
little, the code is essentially the same:
import time, psyco
from psyco.classes import __metaclass__

class Person:
def __init__(self, count):
self.count = count
self.prev = None
self.next = None
def shout(self, shout, deadif):
if shout < deadif:
return shout + 1
self.prev.next = self.next
self.next.prev = self.prev
return 1

class Chain:
def __init__(self, size):
self.first = None
last = None
for i in xrange(size):
current = Person(i)
if self.first is None:
self.first = current
if last is not None:
last.next = current
current.prev = last
last = current
self.first.prev = last
last.next = self.first
def kill(self, nth):
current = self.first
shout = 1
while current.next != current:
shout = current.shout(shout, nth)
current = current.next
self.first = current
return current
def main():
ITER = 100000
start = time.time()
for i in xrange(ITER):
chain = Chain(40)
chain.kill(3)
end = time.time()
print ''Time per iteration = %s microseconds '' % ((end - start) *
1000000 / ITER)

psyco.full()
main()

us = microseconds
On my PC (that seems similar to his one) this version needs about 38.9
us/iter instead of 189.

On my PC the Java version takes 1.17 us, while the C++ version (with
MinGW 4.2.1) takes 9.8 us.
A raw D translation needs 14.34 us, while a cleaned up (that uses
structs, no getters/setters) needs 4.67 us.
I don''t know why my C++ is so much slow (doing the same things to the C
++ version doesn''t change its running time much).

Bye,
bearophile


Jack wrote:

I know one benchmark doesn''t mean much but it''s still disappointing to see
Python as one of the slowest languages in the test:

http://blog.dhananjaynene.com/2008/0...-jruby-groovy/

Just ignore that. If the code had been designed for Python from the start, it
would have performed a lot better.

Currently it looks like syntax-adapted Java code to me.

Stefan


这篇关于基准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆