ajwang / groovypptest

Automatically exported from code.google.com/p/groovypptest
0 stars 0 forks source link

Slow list.find { condition } #392

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
def start = System.currentTimeMillis()

def strings = ['a', 'b', 'c']
def count = 10000000
for (i in 0..count) {
  strings.find { it == 'c' }
}

println (System.currentTimeMillis() - start)
start = System.currentTimeMillis()

for (i in 0..count) {
  for (c in strings) {
    if (c == 'c') {
      break
    }
  }
}

println (System.currentTimeMillis() - start)

------------------

When using strings.find { it == 'c' }, the performance is about 10 times slower 
than when using the second, inlined version. The profiler reports that the most 
time is spent in DefaultTypeTransformation.booleanUnbox inside the closure. Is 
this necessary?

Original issue reported on code.google.com by gromop...@gmail.com on 1 Aug 2011 at 9:03