Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!dimacs.rutgers.edu!bcm!rice!uw-beaver!sumax!amc-gw!pilchuck!dataio!fnx!nazgul!bright From: bright@nazgul.UUCP (Walter Bright) Newsgroups: comp.lang.c Subject: Re: lookuptables vs switch(x) Message-ID: <170@nazgul.UUCP> Date: 20 Nov 90 04:24:16 GMT References: <1351@umvlsi.ecs.umass.edu> Reply-To: bright@nazgul.UUCP (Walter Bright) Distribution: usa Organization: Zortech, Seattle Lines: 14 In article <1351@umvlsi.ecs.umass.edu> breck@star.ecs.umass.edu (Liam Breck) writes: /I need to use one value to get a string from a list of values and /strings about 30 elements long. I can think of two ways of doing it: /using an array of structures and a loop to search the array for the /desired value or a switch statement with 30 case labels. Which is /faster? If I put the switch in its own function how much will that /slow things down? Your results will vary greatly depending on your target machine and the compiler used. Your best bet is to try it both ways and time the results for your configuration. I'd suggest looking at the routines bsearch() to search a table and strchr() which can also be used for that if the values are all < 256.