4 ms·
If I read the OP correctly the benchmark used an implementation of the Longest Common Subsequence algorithm, expected to run in O(n³) time and O(n²) space. It's
by YeGoblynQueenne 10y ago
If I read the OP correctly the benchmark used an implementation of the Longest Common Subsequence algorithm, expected to run in O(n³) time and O(n²) space. It's a dynamic programming algorithm and so not quite trivial, but, hey, it's an algorithm. The coding is never the biggest complication with those.
As a benchmark it's probably OK, but language benchmarks in general are never very useful. Like, the op essentially makes the claim "you can't code this any faster in X language". Well, maybe you can't, but someone else can. Unless you have a way to run exactly the same code in n languages, or somehow produce exactly the same binary from n languages, then there's no real comparison, sadly.
But- we're programmers and that sort of thing is our favourite sport, innit.
- corndoge 10y agoIf you produced the exact same binary the language that was used to produce it would be inconsequential, no?
- YeGoblynQueenne 10y agoHah. You're right, missed that. But that's the point, isn't it? You can't ever compare two programs written in different languages claiming to test "the same program" written in different languages. Because in the end either they're not the same program, so there's no comparison, or they're the same program, so what are you really comparing?
- jdright 10y agoI think the reason of comparing two programs in two different languages is exactly to have an idea of how expressive one language can be to generate a performing program given its inputs and outputs are the same, the way on which the code is written is the second factor being evaluated. The benchmark game is the perfect exemple of this, anyone can write a better version of a program and improve the language "score" until no one will be able to improve it. At this moment we can see how the language design impacts the resulting program. This should be the only way to compare languages.
- YeGoblynQueenne 10y agoSomething else that struck me as wrong: the op counts the time the JVM needs to startup in the time it takes for the program to complete. That should be completely wrong, right? Otherwise we should count the time the physical machine took to boot up -and then the OS to load- in the time each benchmarked implementation took to complete. The JVM is a virtual computer, so why treat it any different than the physical one?
- jdright 10y agoNo. The JVM should be included too as it is part of what the language needs to run. If you wanna compare including the boot of the real machine, then go for it as to run the JVM you still need a real machine to boot, but then you're adding noise as the machine is the same for the two programs and can, due external out of control reasons, have different timings. But still, JVM IS part of the language and the program unless you compile to native.
- ygra 10y agoTo add to this: The same goes for C's process startup (at least the OS won't call main with those arguments; the C stdlib performs some tasks before your code runs), or interpreter startup. Unless you're writing in assembler and call the OS directly, almost every programming language will have some overhead when starting. Granted, managed languages like Java are much worse than many others.
- benchaney 10y agoThis is true, but any overhead that C has Java will also have because the JVM is itself an ELF binary.