Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

10. The Class Library, Part 1 > Integer Efficiency - Pg. 322

Integer Efficiency There are two principles that underlie the efficient use of integers: · Any given CPU will operate slightly faster if the integer size matches the register size. · Multiplication is about twice as fast as division. From these two principles, we can derive some basic heuristics: Use an Integer unless you have a good reason not to Most modern desktop computers have 32-bit processors, so a 32-bit integer will provide the best performance. But, of course, this is subject to change over time. Replace division with multiplication in time-critical sections of code Don't obsess over this one, but if you're going to perform the same operation 10,000 times, it can make a difference: And one final tip: You may have noticed that the unsigned integers ( UInt32 , etc.) are not CLS-compliant. They'll work fine in a pure Visual Basic application running on a Windows operating system, but you may run into problems if you're using multiple languages or porting to a different version of the .NET Framework. You might not care, but these things do have a way of coming back to haunt you. My advice would be to avoid the unsigned integers without a very good reason. 322