Linux Today: Linux News On Internet Time.
Search Linux Today
Linux News Sections:  Blog -  Developer -  High Performance -  Infrastructure -  IT Management -  Security -  Storage -
Linux Today Navigation
LT Home
Preferences
Contribute
Link to Us
Search
Linux Jobs

Linux Today
Enterprise Linux Today
Apache Today
JustLinux.com
Linux Planet
PHPBuilder
All Linux Devices
Technology Jobs

JustTechJobs.com

LinuxToday Newsletters
Server Daily
IT Management Daily
Subscribe News
Subscribe PR
Subscribe Security

internet.com
Internet News
Small Business

Advertise
Newsletters
Tech Jobs
E-mail Offers

 






Current Newswire:

A tale of two distros: Ubuntu and Linux Mint

Raspberry Pi benchmarked against Beagleboard, low price is long term

20 popular Ubuntu Linux apps you may want to try

A Selection of the Very Best Open Source Tutorials and Tools

Android Ice Cream Sandwich ported to x86 tablets, netbooks and notebooks

SECURITY: Google Chrome 17 Improves Security

How to read a CSV file in Perl?

Red Hat Brings Gluster to Amazon Cloud

New Linux kernel fixes power-saving issues

Using Wii remote with Android Device- Taking Gaming to the Next Level



Applications Management Engineer Sr (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
:Optimizing Switch-Case Statements In C For Speed
Optimizing Switch-Case Statements In C For Speed
Feb 2, 2009, 03 :04 UTC (6 Talkback[s]) (7675 reads)

[ Thanks to Safer Code for this link. ]

"This is because a cascading if-else block will check for each condition in each iteration until it reaches the correct one. On the other hand, switch-case blocks are "supposed to" (why supposed to, we'll see just now) just execute the correct statement and move on. "Optimization Technique 1: Keep the case label values close and small (Answer to "supposed to")

"Actually switch-case statements are also many times changed into if-else cascades by the compilers. This happens when the case label values are too far apart and/or are spread over a fairly large range. If you have a small switch-case statement like below, then the compiler will generate a jump-table instead of the if-else cascade."

Complete Story

Related Stories:
Validating Untrusted Integer Inputs(Jan 16, 2009)
int main() vs void main()(Jan 09, 2009)
A New Way of Sleeping in the Linux Kernel(Oct 02, 2008)
Developing Software on an Open Source Stack(Aug 21, 2008)


Index Mode   |   Flat Mode   |   Thread Mode   |   Thread Flat  
  Talkback(s) Name  and Date
1. actually, most modern/decent compiler ...   actually...   
daniel
Feb 2, 2009, 05:26:13
 
> 1. actually, most modern/decent compil ...   Re: actually...   
Rainer Weikusat
Feb 2, 2009, 12:16:59
 
>> 1. actually, most modern/decent compi ...   Re: actually...   
Jose_X
Feb 2, 2009, 12:21:25
 
Just curious, but what projects /do/ you ...   Jose_X   
jeremy
Feb 2, 2009, 14:10:37
 
> Just curious, but what projects /do/ y ...   Re: Jose_X   
Jose_X
Feb 2, 2009, 15:56:36
 
> > Just curious, but what projects /do/ ...   Re: Re: Jose_X   
jeremy
Feb 3, 2009, 02:19:09
 
  Home | Search Talkbacks | Customize View    Top of Page  



Enter your comments below:

* Your Name:

* Your Email Address:

* Subject:

CC: [will also send this talkback to an E-Mail address]

* Comments:

Tags allowed:<I>,<B> and <U>. See our talkback-policy for more about talkback content.

Fields marked with * are required!

..............................




All times are recorded in UTC.
Linux is a trademark of Linus Torvalds.
Powered by Linux, Apache and PHP