Re: [Widelands-public] Loops / Efficiency
Status: Beta
Brought to you by:
sirver
From: Florian W. <Flo...@pf...> - 2006-08-17 22:03:38
|
The following mail thread (from 2003) is quite interesting in this regard,= =20 especially the consideration of data and instruction caches: http://compilers.iecc.com/comparch/article/03-02-073 Am Donnerstag, 17. August 2006 00:00 schrieb Christoph Mallon: > Disclaimer: IAACC (I Am A Compiler Constructer) OK, I can't and won't compete with that background, I'm a mere user :-) It= =20 also seems my information was out of date (or maybe not, cf. the above mail= =20 thread) > IIRC gcc only includes -fomit-frame-pointer automatically on > architectures where doing so doesn't interfere with debugging, i.e. on > x86 it doesn't do it automatically. At -O1, yes. At -O2/3 it's always on. > I don't consider calculation the loop bounds directly before the loop > "unreadable", Neither do I.=20 > sometimes quite contrary: it can break one monster line=20 > into two or three short lines. Which it does decidedly not do in this case. Tell me about readability of t= he=20 following blocks (that's rhethorical; I hereby rest my case). >>> const Descr_Maintainer<Building_Descr>::Index nr_buildings =3D >>> get_nr_buildings(); >>> for (Descr_Maintainer<Building_Descr>::Index i =3D 0; >>> i < nr_buildings; ++i) { >>>----------------------------------------------- >>> for (Descr_Maintainer<Building_Descr>::Index i =3D 0; >>> i < get_nr_buildings(); ++i) { > When you've got the best algorithm, all that's left are the constants. > And for the reasons I stated above the statement "most compilers will do > anyway" is bold. OK, I was sufficiently interested to blow some time for creating numbers. I= =20 stopped very quickly though. Tribe_Descr::parse_buildings (which is the context we're talking about) is= =20 called once when loading a tribe, and nowhere else. This is only done once= =20 when starting a new game. The actual for loop is being called 63 times for= =20 the barbarians (which might itself be a sign of a problem because there's=20 only 45 barbarian buildings). So unless this method does a lot of work (which it doesn't - gprof shows <1= =20 microsecond total accumulated time) I totally ignore those 63 calls. It's n= ot=20 worth the trouble. <pause> Yes, I really mean that. If the profiler doesn't tell me otherwise, I don't= =20 even _consider_ performance on a sub-"which algorithm/datastructure"-level.= =20 http://www.cookcomputing.com/blog/archives/000084.html summarizes my point= =20 better than I could. I think highly of Erik for considering performance. My *personal* view is t= hat=20 *in this case* readability takes the upper hand. I sincerely hope I didn't= =20 express this more strongly than it it was meant. =2D-=20 Mit freundlichen Gr=FC=DFen, =46lorian Weber PGP key id: A34C32F9 =2D-=20 With best regards, =46lorian Weber PGP key id: A34C32F9 |