Php Groovy/Grails读取大型csv文件的速度很慢

Php Groovy/Grails读取大型csv文件的速度很慢,php,csv,grails,groovy,Php,Csv,Grails,Groovy,我有一个很大的csv文件(168MB,149K行,125列)。 我想用以下代码得到第三列的和: def tot = 0 new File("/path/to/big/file.csv").splitEachLine(";") { row -> try { tot += row[2].toBigDecimal() } catch(Exception e) {} } println tot 这需要11秒: root@front1:~# time groov

我有一个很大的csv文件(168MB,149K行,125列)。 我想用以下代码得到第三列的和:

def tot = 0

new File("/path/to/big/file.csv").splitEachLine(";") { row ->
    try {
        tot += row[2].toBigDecimal()
    } catch(Exception e) {}
}

println tot
这需要11秒:

root@front1:~# time groovy test.groovy
8691797.09805144

real    0m10.965s
user    0m9.977s
sys     0m0.500s
root@front1:~#
我用php编写了一个类似的代码,在同一台机器上只需2秒钟就能得到相同的结果

为了获得相同的执行时间,我应该在groovy/grails中执行任何调优或更好的代码吗

谢谢


Groovy版本:2.3.8 JVM:1.6.029供应商:Oracle公司操作系统:Linux

显然php更好:=-)eh好的一点,我尝试用ruby实现相同的例程,我得到了10秒的执行时间(与Groovy/grails相同),而golang编译的实现与php一样需要2秒,我不明白发生了什么……你考虑过groovy的启动时间了吗?这似乎是
@CompileStatic
使用file.withReader并不能提高性能的绝佳选择。正如我看到的bootleneck是拆分或标记化函数,它们速度很慢。我尝试使用indexOf和substring在前3个匹配后停止(得到第三列),使用这种方法执行时间下降到2秒。。。