5 ms·
How about Java? It is quite funny Java version is much faster than Python version even when Python version does use C ? Something fishy going on.
by 0xFFC 10y ago
How about Java? It is quite funny Java version is much faster than Python version even when Python version does use C ? Something fishy going on.
- Anderkent 10y agoThe java one doesn't do as much as the python one: `line.split(',')` doesn't handle quoted commas, escape characters, different csv separators, etc.
- andrepd 10y agoYeah, calling from python introduces a layer of inefficiency.
- justin66 10y agoIt's as if there's more to software quality than the choice of tools.
- jerf 10y agoThere's nothing mysterious about the Java version... that's not a CSV parser. The other two things are truly CSV parsers. (Inasmuch as there is such a thing for such an ill-defined format. (No, the RFC is not determinative.)) It's easy to be faster if you do fundamentally less. Not necessarily wrong, depending on your task, but it's not comparable.
- __s 10y agoThe java source is using str.split(',') which is completely different than Python's offering of dialect/delimiter/etc https://github.com/python/cpython/blob/master/Lib/csv.py#L24 https://github.com/python/cpython/blob/master/Lib/csv.py#L24
- nradov 10y agoThe Java code is defective. It's not checking for double quotes. The CSV format allows for commas inside column values by surrounding with double quotes, and then you can also put double quotes within such values by escaping them as double double quotes. Fix those defects and the Java code will be a little slower. With modern JVMs, Java can occasionally actually be faster than native compiled languages due to dynamic optimization at runtime.
- dalke 10y agoA few minutes ago (and after your comment) one of the commenters of that issue tested against Apache Commons CSV and found that Java was 1.9x faster than Go, rather than the original 3x: https://github.com/golang/go/issues/16791#issuecomment-244562984 https://github.com/golang/go/issues/16791#issuecomment-24456...
- merb 10y agoactually the java one is still amazing since it's a cold jvm. when it would be a big file I would think that java is far ahead of both. with an aggressive jit. maybe pypy is faster than all 3 :D
- jsiep 10y agoBesides the point that the Java example is not a good one; The JVM is actually a pretty mean piece of software with a lot of optimisation. So while Go could in theory produce faster code then Java I doubt the Go compiler is clever enough to produce faster code then the JVM in a lot scenarios (at the moment).
- jakub_h 10y agoBut Java conceptually has a lot of drawbacks that require the JVM to have screaming performance to compensate for. Almost everything being a "headered" object being probably the worst offender. Even a slightly worse Go compiler is probably well compensated-for by denser data structure layout in the operating memory.
- eternalban 10y ago> Java conceptually has a lot of drawbacks In what sense is an articulated object a "conceptual drawback"? It is a richer object model and SMI and friends had the engineering chops to makes it highly performant.
- weberc2 10y agoWhat do you mean by "a richer object model". The drawbacks are principally that the programmer has less control over allocs and layout.
- jakub_h 10y agoIf you want an actual rich object model, why aren't you using CLOS instead? Java's objects costs you a lot of potential performance with few of the benefits.
- pjmlp 10y agoOnly true until value types get productified and there are already prototype versions to play with. Also depending on which JVM SDK is being used (Oracle Hotspot, Oracle Graal, IBM J9, HP, PTG, JET,...), the quality of escape analysis differs but it all boils down to turning those headered objects into plain structs, if possible stack allocated.
- masklinn 10y agoThe Java version is just reading lines and splitting them on commas, it's not actually a CSV parser.