我对测试groovy++在普通groovy上的性能增益很感兴趣。我找到要测试的脚本
class Chain
{
def size
def first
def init(siz)
{
def last
size = siz
for(def i = 0 ; i < siz ; i++)
{
def current = new Person()
current.count = i
if (i == 0) first = current
if (last != null)
{
last.next = current
}
current.prev = last
last = current
}
first.prev = last
last.next = first
}
def kill(nth)
{
def current = first
def shout = 1
while(current.next != current)
{
shout = current.shout(shout,nth)
current = current.next
}
first = current
}
}
class Person
{
def count
def prev
def next
def shout(shout,deadif)
{
if (shout < deadif)
{
return (shout + 1)
}
prev.next = next
next.prev = prev
return 1
}
}
def main(args)
{
println "Starting"
def ITER = 100000
def start = System.nanoTime()
for(def i = 0 ; i < ITER ; i++)
{
def chain = new Chain()
chain.init(40)
chain.kill(3)
}
def end = System.nanoTime()
println "Total time = " + ((end - start)/(ITER * 1000)) + " microseconds"
}它起作用了。但如果我想加入
@Typed在第一个类名和运行之前,我得到了错误:
#groovy groovy.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/melco/test/groovy.groovy: 18: Cannot find property next of class Object
@ line 18, column 22.
last.next = current
^
1 error# groovy -version
Groovy版本:1.7.5JVM: 1.6.0_18
知道为什么吗?
发布于 2011-01-02 12:38:54
要享受静态类型编译,需要至少提供一定数量的类型信息。
通常,只需定义属性类型(在您的示例中是prev )和方法参数类型就足够了。
发布于 2011-06-21 14:35:02
您声明的所有变量都是java.lang.Object类型(在本例中为grovy.lang.Object )。所以他们没有“下一步”等方法。
尝试使用Person current = new Person()和Cain current = first等。
https://stackoverflow.com/questions/4578131
复制相似问题