Path: utzoo!attcan!uunet!samsung!sdd.hp.com!decwrl!sgi!shinobu!odin!cashew.asd.sgi.com!kurt From: kurt@cashew.asd.sgi.com (Kurt Akeley) Newsgroups: comp.sys.sgi Subject: C switch performance Message-ID: <1990Oct4.173210.9511@odin.corp.sgi.com> Date: 4 Oct 90 17:32:10 GMT Sender: news@odin.corp.sgi.com (Net News) Reply-To: kurt@cashew.asd.sgi.com (Kurt Akeley) Organization: sgi Lines: 141 In the interest of creating a _really_ fast display list format for the VGX graphics, I have been experimenting with various token parsing schemes. Of particular interest is a simple switch statement, looping through an array of integer tokens. To test performance, I wrote a test loop and timed it with several different variations. The base test code is: ******************************************************************************* /* * Kurt Akeley * 4 October 1990 * * Test performance of C switch statement */ #include #include #include #include #define MAXTOKEN 20 #define ARRAYLEN 10000 #define MAXLOOP 1000 long dummy = 0; long tokens[ARRAYLEN]; main() { register i; /* generate random values in an array */ srand(1); for (i=0; i<(ARRAYLEN-1); i++) tokens[i] = ((float)rand() / 32767.0) * MAXTOKEN; tokens[ARRAYLEN-1] = MAXTOKEN; /* time the switch operation */ startclock(); for (i=0; i