From: Nicholas N. <nj...@ca...> - 2003-03-17 12:37:56
|
On Mon, 17 Mar 2003, Christian Leber wrote: > I saw this realy big switch(opt){case 0x00....} statement and thought > "this must be slow". > > So I tried the "Labels as Values" feature of the gcc. > (http://www.dis.com/gnu/gcc/gcc_79.html#SEC79) > Yes it is a gcc feature, but because is specially for x86/Linux I can't > see a problem. [snip] > 13.54 -> 12.55 > that is a speedup of about 7% in this case > > If you (Julian or Nick) are perhaps interested in it, I would clean it up > further and remove this one switch() { } statement. Interesting. Two comments: 1. Can you try it with a few other programs? It would be nice to see if the 7% speedup is consistent across programs. Some programs I've used for performance timing in the past: gzip bzip2 latex konqueror (startup then quit immediately) Batch programs are obviously more suitable for this. 2. The bottom of the webpage you mention says: "An alternate way to write the above example is static const int array[] = { &&foo - &&foo, &&bar - &&foo, &&hack - &&foo }; goto *(&&foo + array[i]); This is more friendly to code living in shared libraries, as it reduces the number of dynamic relocations that are needed, and by consequence, allows the data to be read-only." Valgrind is packaged as a shared library. Perhaps this might improve things further? If you could try these two experiments, and tell us the results, that would be very helpful. Thanks. N |