利用Groovy1.1 beta-3和Groovy1.1 beta-2將8皇后代碼各運行10次,記錄下運行程序所耗時間,結(jié)果如下:
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ????? AVG | |
Groovy 1.1-beta2 | 1250 | 1250 | 1313 | 1203 | 1359 | 1219 | 1218 | 1297 | 1281 | 1344 | 1273.4 |
Groovy 1.1-beta3 | 1156 | 1078 | 1015 | 1047 | 1047 | 1156 | 1094 | 1031 | 1157 | 984 | 1076.5 |
經(jīng)過計算,Groovy1.1 beta-3的性能提升了15.5%,期待Groovy1.1 final :)
此外值得一提的是,IBM的ProjectZero團隊正在為Groovy改善Eclipse插件,Sun也向Groovy Team施加援手提供服務(wù)器供其使用,JetBrains的IntelliJ IDEA Groovy & Grails插件milestone2版本已經(jīng)發(fā)布。
測試所用的8皇后代碼:
q = 8
i = new int[q]
count = 0
def scan(n){
??? if (n == q){
??????? println(i.toList())
??????? count++
??????? return
??? }
??? i[n]=0
??? while (i[n] < q){
??????? i[n] = i[n]+1
??????? if (check(n))
??????????? scan(n + 1)
??? }
}
def check(n){
??? if (n > 0)
??????? for (j in 0..<n)
??????????? if (i[j] == i[n] || i[j] - i[n] == j - n || i[j] - i[n] == n - j)
??????????????? return false
??? return true
}
long t1 = System.currentTimeMillis()
scan(0)
long t2 = System.currentTimeMillis()
println("total time:" + ( t2 - t1))? // 耗時
println("total results:" + count)
下載地址:http://dist.groovy.codehaus.org/distributions/groovy-binary-1.1-beta-3.zip
附:朝花夕拾——Groovy & Grails