From: vasudevram Date: 2006-07-27T00:20:06+09:00 Subject: Re: For performance, write it in C > > On Wed, 26 Jul 2006 17:47:13 +0900, Peter Hickman wrote: > > > In this post I want to clear some things up and provide benchmarks as to > > > why you should take "Write it in C" seriously. Interesting series of messages! Got to save and read them through at leisure ... Just adding my 2c: [I worked on a fairly complex performance tuning job once, involving HP-UNIX boxes (multiple), Informix ESQL/C batch programs, IBM MQ series (now called Websphere MQ), UNIX IPC, and got a chance to do tuning at several different levels - SQL queries, MQ logs/partitions, the C code, algorithms in it, etc. Was very educational ... just sharing some insights gained from that, from reading on the subject, and from smaller hobby projects tuning my own code ...] [Not implying that previous posters on this thread haven't done any of the below]. Performance tuning in general is *very* complicated. Guesses or assumptions like "this code tweak should make it run faster" often do not work. The only way is a (semi)scientific approach to measure/profile, study profile results, make hypotheses, change code accordingly, then re-measure to see if the change made a difference. Tuning can be done at any of several different levels, ranging from: - hardware (even here, not just throwing more boxes or faster boxes at the problem, but things like hardware architecture - obviously only if the skills are available and the problem is worth the effort) - software architecture - algorithms and data structures optimization - plain code tuning (things like common subexpression elimination, e.g. using C syntax, changing: for (i = 0; i < getLength(my_collection); i++) { /* do something with my_collection[i] */ } to collLength = getLength(my_collection); for (i = 0; i < collLength; i++) { /* do something with my_collection[i] */ } /* which removes the repeated/redundant call to the function getLength() */ Jon Bentley's book "Writing Efficient Programs" is a very good book which discusses rules, examples and war stories of tuning at almost all of these levels, including really excellent advice on code-level tuning, which may sometimes be the easiest one to implement on existing code. Though the examples are in a pseudo-Pascal dialect (easily understandable for those knowing C), and though it may be out of print now, for those who have a real need for tuning advice, its worth trying to get a used copy on eBay, from a friend, whatever. Its chock-full of code examples with the tuning results (verifiied by measurement, as stated above), when (and when not) to apply them, and the war stories are really interesting too ... Googling for "performance tuning" and variants thereof will help ... There's another book (for Java, mostly server-side programming) by a guy called Dov (something - forget his last name and the book title, if I remember it, will post here) that's *really* excellent too - he shows (again, with actual measurements) how some of the "expected" results were actually wrong/counter-intuitive. He worked with IBM on the web software for one of the recent Olympics. HTH Vasudev ---------------------------------------------------------------------------------- Vasudev Ram Custom utility development in UNIX/C/sh/Java/Python/Ruby Software consulting and training http://www.dancingbison.com ----------------------------------------------------------------------------------