Chris Baus

Python, Ruby, and scripting performance

Joel Spolsky stirred up the Ruby community (which is genius since he just launched his new job board) by claiming that he hasn't used Ruby because it is too slow. I want to throw in an anecdote based on my own experience.

Amoung other projects, I get paid to work on a large desktop application for the financial industry. Advanced graphics is a differentiator in our market, hence the product includes a custom 2D charting engine. A couple years ago marketing came with a request: change the fonts in all charts with one command. A simple attempt was made, but it was extremely slow.

We couldn't ship it because of poor performance. As RedMonk analyst Stephen O'Grady claims: speed is a feature. I inherited the project and spent the next 6+ months with another developer reworking the application's font and text rendering. Joel is right. Performance does matter.

Ruby is slow, but so are most dynamic language implementations.I've been working on a list implementation for C++. Lists are one of the fundamental data structures used by developers, so it is worth while to optimize them. My primary motivation was to limit memory failures in SwitchFlow while maintaining C++'s object semantics, and I ended up with the side benefit of increased performance.

I compared C++'s list performance with Ruby's and Python's. I believe we will see dynamic language (duck typed or whatever) runtime optimizations outperform statically bound languages such as C++, but we aren't there yet. With garbage collected memory it is possible that the runtime could limit heap access and boost performance, and I hoped Python and Ruby would hold their own. That was a pipe dream. With 50 million inserts, 50 million deletes, and 50 million length operations, C++ trounced Python and Ruby. On my Linux box, with a Celeron D processor, my pooled_list took around 3 seconds, and the standard C++ list came in around 7 seconds. Python and Ruby both clocked 90-100 seconds -- at least a factor of 10 difference.

Here are the test programs if you want to try them yourself.

pooled_list_performance_test.cpp (~7secs standard ~3.5secs pooled) (~100 secs)

testlist.rb (~100 secs)