Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: towards a faster isdigit() Message-ID: <719@taumet.com> Date: 9 May 91 00:02:42 GMT Article-I.D.: taumet.719 References: <1991May8.030515.7004@twinsun.com> <716@taumet.com> Organization: Taumetric Corporation, San Diego Lines: 25 I wrote: |eggert@twinsun.com (Paul Eggert) writes: |>Why not use the following implementation instead? |> #define isdigit(c) ((unsigned)((c)-'0') < 10) |>This needs just a subtraction followed by a comparison. It's faster on |>all the systems I've tried it on, and is strictly conforming ANSI C. |Maybe you didn't try it on enough systems :-) |The macro you suggest requires a test and jump, and on some modern RISC |machines the penalty is very high. Bruce Evans pointed out to me that since isdigit() is used in tests, the test-and-jump is already paid for. I checked my test code to see why I got the results I did, and found they were the opposite of what I reported. I'm sorry for wasting everyone's time with this. Paul's macro is indeed faster. -- Steve Clamage, TauMetric Corp, steve@taumet.com