timer = { closure ->
start = System.currentTimeMillis()
closure.call()
println System.currentTimeMillis() - start
}
// define an array with value 1 to 100000
def rates = 1..100000
println 'Performing 1st Test with .times'
timer {
def a = 10
def b = 2
100000.times {idx-> a*rates[idx] }
}
println 'Performing 2nd test with for'
timer {
def a = 10
def b = 2
for(int i=0;i<100000;i++) {
a*rates[i]
}
}
Labels: Groovy
Why kopi house? The word kopi means coffee in our dialect and since Java symbolic icon is a cup of coffee, so this is why I named my blog as kopi house (Java with local favour) ; )
Subscribe to
Posts [Atom]