From: Gavin Kistner Date: 2005-06-18T09:41:44+09:00 Subject: Re: Super-scalar Optimizations On Jun 17, 2005, at 10:18 AM, Ben Giddings wrote: > On Thursday 16 June 2005 19:00, Phrogz wrote: >> His answer was "no", and involved discussion of super-scalar >> architectures and the fact that the original way ran the >> assignment in >> parallel to the condition evaluation, and so was in fact faster. >> > > Yay! Trying to outsmart a compiler! > > This sure seems like premature optimization to me. Was it really > slowing > things down to do it the more obvious way? Had that been proven > using a > profiler? I appreciate your comments, but in the defense of my coworker: 1) As I've stated, using the boolean flag to run the code once was only a hack to test if the solution would fix, and 2) No, I doubt that the placement of a single boolean assignment made any measurable difference either way. My point with this thread (which has been answered) was simply to find out if Ruby had any similar things to keep in mind that would flow down to the instruction pipeline architecture. The placement of that assignment in the C++ code > Since computers are so smart, these days it makes more sense to > write code > that a human can understand. Unless you truly need to clarify > things for > the computer (i.e. things run too slow when they're written in the > human-obvious way) don't write for the computer! FWIW, I don't think that the difference between: if ( !foo ) { bar( ); foo = true; } versus if ( !foo ) { bar( ); } foo = true; makes a difference either way in terms of legibility. Being against premature optimization is fine to a point, but in any programming project there are numerous basic choices one can make which will affect performance.