From: Peter Hickman Date: 2006-07-28T17:35:47+09:00 Subject: Re: For performance, write it in C Tim Bray wrote: > So, first gripe: C is faster than Ruby *in certain problem domains*. > In others, it's not. > The post was about people wanting better performance for their code. Quite clearly if the code you have written in Ruby (or whatever) runs fast enough for you then performance is a non issue. If however the performance of your code is an issue then in truth there is only so much improvement that you can squeeze out of Ruby, if that is enough to resolve your performance issues then fine. If you want still more performance then you want to write it in C (or perhaps buy some new hardware :) ) > Second gripe. The notion of doing a wholesale rewrite in C is almost > certainly wrong. An earlier project of mine used GD from Ruby to calculate some colour metrics from images and write them into a database. I rewrote the whole thing in C, using the same GD and SQLite2 libraries as the Ruby version, and the improvement was massive. Despite the fact that the Ruby was not actually doing very much. Most of the time was spent in the GD library, so I am not all that convinced that rewritting part of a project in C will achieve quite the same improvement. And if you are going to convert a significant chunk of code to C then you may as well go the whole hog. > In fact, the notion of doing any kind of serious hacking, without > doing some measuring first, is almost always wrong. The *right* way > to build software that performs well is to write a natural, idiomatic > implementation, trying to avoid stupid design errors but not worrying > too much about performance. If it's fast enough, you're done. No problem here. > If it's not fast enough, don't write another line of code till you've > used used a profiler and understand what the problem is. If in fact > this is the kind of a problem where C is going to do better, chances > are you only have to replace 10% of your code to get 90% of the > available speedup. Not been my experience to date but then perhaps I am not working on problems that can be solved in that way.