Benchmark: Java, Python, PHP, C, JavaScript, Swift, Ruby, Perl, Go, Lua, Rust
benchmarksgame.alioth.debian.org
benchmarksgame.alioth.debian.org
If you think some language is misrepresented in that benchmark, you can submit your own solution.
I don't think the parent doubts the runtimes or is claiming that the code for his pet language wasn't written properly and therefore the site is a sham. The issue is: what is reasonable code?
Benchmarks invariably become a game of massaging the code to produce the optimal assembly. And that's the problem. The reason that we invented higher level languages was so we could stop thinking about assembly. The point of most higher level languages is not to optimize CPU cycles, but to optimize human brain cycles. If we only cared about speed (and not at all about development time), we would just write all code in assembly.
I am not particularly interested in how fast meticulously fine tuned code in a given language runs. I have no doubt that, given enough time, an excellent programmer can finely craft a block of code to run very fast in any half decent language. And this site is evidence of that.
What I want to know, and what benchmarks never show, is which languages make writing performant code simple, idiomatic, and natural. Which languages give me good performance, without having to really work for it?
This is an amazing site, but it is a stretch to think that it compares languages. It compares programmers and their implementations. The implementations are more like their own art form, like Chess or something.
We could always take the parent at their word -- "Now i know these are Potemkin-village level stunts and political maneuvering by language activists and staff of that site.".
Or the ruby ones. Not much like ruby I have ever seen. It's not particularly difficult to write C code that can be easily called from ruby which is why I guess most ruby programmers wouldn't bother to write code like this in ruby. If you want C, just write C!
I think all the implementations are straightforward as implementations. But few are the most idiomatic way to express the alogorithm in that language.
Specifically which "ruby ones"? (Currently 37 programs are shown.)
>> the most idiomatic way <<
One person's idiomatic is another person's idiotic.
I'm not sure how much evidence is needed. It seems obvious that people who are fans of language X are going to submit code with the sole intention of bumping up performance at any cost.
The site is still interesting, but probably useless for real world decision making.
That's just name-calling.
As someone that works predominantly in a language long considered passé (Perl), I always kinda relish seeing that it is still faster than Python and Ruby for many problems. As Python and Ruby have gotten faster, I'd sort of assumed they were both notably and clearly faster than Perl, by now, but that's not the case though the difference is now quite small and probably debatable.
Decades ago it was open and written in Perl. Then it was rewritten in Python and closed down. Go figure.
And you even comment on that usage in your code.
>> Decades ago it was open and written in Perl. Then it was rewritten in Python and closed down. Go figure. <<
At best your comment is disingenuous.
You can download the Python measurement scripts, use them with luajit, nim, crystal, pypy, truffle-graal or Perl6 programs and publish the measurements.
You don't. Go figure.
I assumed the sources were available, somewhere, but until I went looking for it, I wouldn't have been able to say so with confidence. That's not an obligation, of course...volunteers should feel free to do whatever they want with their projects. But, if you wanted to keep the community involvement the game had historically, linking source in the lingua franca of the day (github or gitlab, or whatever, seems pretty standard today) would go a long way.
Perhaps it's merely a reflection of wanting some one else to do work we choose not to do.
(You'll find that there already are duplicates of the benchmarks game repos on github).
Entirely valid position to take. There's only so many hours in a day, so many days in a year, and so many years in a life.
Do it the way you want to do it. Unless someone is paying you or you want their specific help with something going forward, I don't see any obligation on your part to listen to demands.
The problem is not that someone else can do it, the problem is YOU need to do it. You got the name reserved for it, you got the machines to do it, you decide to rewrite it and throw them out, no one is looking somewhere else for better and more benchmarks.
The big competitors with better and faster engines have no incentive to match performance when their name is not on the list, and they just publish their own results. Users don't look somewhere else.
That's what it's like now -- trivial but time consuming.
There were pain-points with the old perl scripts (and nested make files) but I would have continued to put-up with the problems and would have continued to use the old perl scripts.
But (back in 2008) I couldn't see how to set-affinity with Perl and I could see how to do that with Python.
That's why I rewrote the measurement scripts in Python.
>> They suck. <<
https://developer.mozilla.org/en-US/docs/Mozilla/QA/Bug_writ...
>> You got the name reserved for it <<
Wow! Think-up a name!
>> you got the machines to do it <<
I have one too-old machine.
>> no one is looking somewhere else for better and more benchmarks <<
55% of page views are from "organic search".
Open Source stuff really only ever has one guarantee: If it breaks, you get to keep the pieces.
You can put it back together any way you want, but you can't demand they give you a new one that meets your expectations. Unless you want to pay them to do so, and they're willing to accept the money and terms.
Dec 2015. Pleased you find it nice to read.
I don't go there often, but it's nice to know there's a way to get a vague understanding of relative performance for languages for those occasions when one needs to know "is it fast enough?"
Thanks to all those who contribute their expertise and their programs.
Ruby was (very) slow back then (notably and measurably slower than PHP, Python, or Perl) and people still loved it. The warts on PHP that got the most bad press were rarely related to performance.
So, yes PHP used to be slower than it is today, by a lot. But, speed wouldn't have immunized it against the criticism leveled against it. All the effort going into fixing performance for PHP coincided with fixing some of the bigger warts of the language, as well...so much of the hate for PHP has dwindled in recent years.
The fact that people building for the web are much less often required to work in PHP also reduces the hate.
Since PHP5, the lead team made progress into making it solid. And in PHP7 some eastern/russian guy hacked the VM a lot. Adding new traits and improving memory usage and performance a lot too.
The "hatred" comes from old days (v3,v4):
- massive inconsistency in naming
- global side effect was a norm
- bugs, bugs, bugs
Combined with the nascent web boom, tons of new kids (that includes me) started having fun with html/php. A large mass of the web was written with it, carrying all the bad design decisions in forms of security bugs and impossibly bad code.ps: I audited one famous wordpress plugin and it was 10 pages long of redundant code in 3 big loops, dead code everywhere, commented code released in production. All this to add a few links here and there.
Facebook hasn't spent a lot of time worrying about their choice of PHP either. Facebook's primary language is Hack, a mostly compatible derivative of PHP. Prior to Hack (~2014) Facebook used traditional PHP, which they reimplemented a couple times for performance reasons. It seems that Facebook has spent its time worrying about how NOT to leave PHP.
Makes one wonder about the value of this daily new programming language era we're in at the moment.
There was some legitimate criticism to be had about PHP 5.x being slow, especially if it wasn't paired with an opcode cache system / accelerator.
But in practice, the Node.js ecosystem is all built around evented I/O and PHP has to execute them one at a time.
(Well, actually with libraries like Kraken and ReactPHP and amp, you can have an event loop, but there are not that many I/O options for you.)
Most of the replies here are stating that PHP is fast. It can be for these kind of benchmarks.
But, it does have the reputation you're suggesting. That reputation, though, is based on the old CGI model. Most php apps are built in a way that all of the initiation and setup code is run for every single request. That makes it comparatively slow.
Some PHP apps get around that by using a shared memory cache, like apcu, to box around that. That helps a lot, but isn't the same as a typical golang or node.js app where startup code is truly run once, and new requests go through a much shorter path.
All of that, though, is less a "language" thing and more of a runtime thing. You can, for example, use Facebook's HHVM+Proxygen and run PHP code in the exact same way as node.js.
PHP also has the best language features and IDE integrations, the only remaining problem is the legacy stdlib and devbase. Ruby with an inliner and method cache would catch up, but I don't see it happen. Python is doomed by its architecture. Perl has a faster interpreter loop, but data structure bloat and similar dev problems as the other 2.
The means that a lot of rather bad (inexperienced?) programmers use it, which means there is a lot of bad PHP code out there.
People see that bad code and assume the language is bad.
The language has some warts and inconsistencies, and people are eager to point them out as justification for their hate. But for real programming most of them hardly matter.
The biggest difference between PHP and the other dynamic languages, though, is that PHP came out with pretty popular stuff like wordpress, joomla, magento or drupal that they all share crappy code coz they all have a large codebase started before PHP managed to fix some stuff starting from version 5.3
This is also becoming less of a distinguishing factor in the container era where the answer for a number of cases is “Extend a base Docker image”.
If you really, really try it's possible in Python, C# and Java too, but ... wtf.
[1] - http://hhvm.com
Yes, startup time is a concern with the JVM, but that's not what it's built for - it's meant for long-runnning repeatable code paths.
There was nothing in the original design that said "only long running server processes". In fact, Java was originally aimed at set-top boxes, then web applets, then cross platform GUI apps. It was only after it failed in all of these that the server was discovered, despite the fact that "write once, run anywhere" is almost completely pointless when you control the hardware it runs on.
The long startup times are a limitation of the implementation technology, not a principled design choice. See also: Jitterdämmerung ( http://blog.metaobject.com/2015/10/jitterdammerung.html )
http://benchmarksgame.alioth.debian.org/sometimes-people-jus...
Note the timings are seconds and tens-of-seconds.
http://benchmarksgame.alioth.debian.org/u64q/program.php?tes...
The measurement shown is 21.54 secs.
The average JMH shows is 23.367 ± 0.062.
My problem with this site it makes poor support of that claim. The data is hidden behind loads of links, and none of the data is visualized at all. Even a few simple bar charts, keeping the hierarchy of the site otherwise unchanged would vastly aid comprehension. The points being made would come across much more easily.
This sort of data is the poster child for visualization, yet this site relegates the data to tables of numbers.
>> Even a few simple bar charts <<
http://benchmarksgame.alioth.debian.org/u64q/which-programs-...
>> would vastly aid comprehension. <<
Is it possible that you are just wrong?
Is it possible that simple bar charts do not aid comprehension but encourage thoughtless instant conclusions?
http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...
Why would it be stunning that a programming language compiled to assembler can beat a broken-by-design interpreted language which doesn't even have integers or arrays? The stunning part is that the people behind node.js have managed to get that much performance.
I assure you that JavaScript is an interpreted language, and it does not have arrays or integers. This is not a harsh statement but a factual one.
(Not sure if you already knew this, but if so, you're not being factual, you're being selectively pedantic to make something sound worse than it is. Lack of ints or arrays isn't a big factor in JS performance for non-pathological cases.)
(edit: reasons for downvotes are appreciated!)
If you don't enjoy JS, it's because you haven't taken the time to learn what's great about it and have gotten hung up on the stupid things other people do with it or you're copying their mistakes.
oh come on now, it's perfectly ok for people to dislike a language for any number of reasons. I don't hate JS but I don't particularly enjoy it, and that could be said for a number of popular languages. it has nothing to do with "taking the time" to learn anything - some people just don't jive with JS and that's totally cool.
The performance implication of JS not having ints is a different matter. In practice, if you write code that treats a variable like an int, modern JS engines will correctly compile that into bytecode where it really is an int, and performance will be as expected.
So the lack of an int type doesn't really hurt performance, though one can argue that it makes it harder to write performant code.
They go on to say:
> If you don't enjoy JS, it's because you haven't taken the time to learn what's great about it and have gotten hung up on the stupid things other people do with it or you're copying their mistakes.
Which is... wrong. Many, many programmers dislike JavaScript and node.js because of its flaws. I don't think Stockholm syndrome is an appropriate prescription.
We are having a discussion is about programming language benchmarks.
A benchmark in this case is a measure of how fast a computer program can run. A computer program is a series of instructions for a computer. These instructions are written in something called a programming language. A programming language which is interpreted is inherently slower than a programming language which is compiled to assembly language. A programming language which does not have integers but must represent all numbers as floating point numbers is inherently slower than a programming language which has integers. A programming language which does not have arrays, but must represent arrays using hash tables, is inherently slower than a language which does have arrays. Thus, Node.js, which is interpreted and does not have arrays or integers, would be expected to be have much lower benchmarks than Go's, and yet node.js has exceptionally high performance.
(edited for negativity and ad-hominem)
It looks like the JS version is using the built in runtime's regex engine.
I don't know exactly why (maybe differences or missing features in go's regex) but the go version is actually using the c FFI to call pcre.h, and without profiling it I'd guess a huge hit is that alone.
Don't guess. Look at the measurements. Look at the source code. That Go PCRE program is faster than --
http://benchmarksgame.alioth.debian.org/u64q/program.php?tes...
Maybe faster still to use some of the techniques from this other Go PCRE program --
http://benchmarksgame.alioth.debian.org/u64q/program.php?tes...
Why can't I compare:
Lua vs LuaGIT
PHP5 vs PHP7 vs HHVM vs Hack
Perl5 vs Perl6
GNU GCC vs Intel C vs CLANG
This new rule "one implementation per language" is so stupid!!!@debian: change it back
Also some languages like, Ruby, do really well on some of these tests because the C-code underneath has been written well (example regexes are just as fast under ruby as they are anywhere else because the underlying C-library kicks ass though I forget the name of it).
And he thinks its no unfair that D is not resented when a lot of people look at his site and think: "If your not here as a language, then the language must be bad".
Good luck on changing his mindset because i have seen topics going back years regarding D not being there.
If you want a more impartial benchmark set:
https://github.com/kostya/benchmarks
And where is D on those tests ;)
No.
> There used to be D benchmarks on the old site
Back in early 2008.
http://web.archive.org/web/20080730204710/http://shootout.al...
Look how many other language implementations were also shown back then and have not been shown since.
> … for some reason the current maintainer has a issue with D
No.
> Good luck on changing his mindset…
Make the measurements you want to see and publish them for everyone else to see.
Lisp hasn't been removed.
(Clojure has. So's Scala.)
http://benchmarksgame.alioth.debian.org/
and click "Lisp".
Therefore, any large-margin differences are benchmarking the programmer not the technology.
I don't think that's a practical claim. Interpreted or JIT compiled languages depend on the interpreter or VM. JavaScript has become much faster over time as JavaScript VMs have improved, independent of the details of any particular JavaScript program. Ruby has become faster over time for the same reason. I've seen Ruby programs I've written speed up significantly without any significant code changes when I moved from an older to a newer version of Ruby.