How to Compare Computer Algorithms

Software developers balance many factors when building applications and websites. In the early days, when computers had little storage and resources, size and speed were the main concerns. Today, with multi-core processors and gigabytes of memory, complexity and maintainability often override performance. Here are some of the main factors to consider when choosing the right algorithms for your project.

Instructions

    • 1

      Measure performance. The first factor that always comes to mind when measuring an algorithm is speed. No one wants to wait for slow software . There are several ways to determine which algorithm will perform best for the task at hand. An algorithm can be measured manually by counting instructions, using probabilities to determine execution paths. Easier still are profilers that count machine cycles as the code runs.

    • 2

      Compare code size. Although not quite as important as performance, the size of the code sometimes does become a factor. Embedded software and mobile apps often need to share limited memory, and browser-based code takes time to download. Sometimes a small hit in performance can be sacrificed to shave a significant amount of code.

    • 3

      Determine the level of complexity. Most commercial software developers write code deployed on desktop PCs or web servers with plenty of processing power and more than sufficient memory. Today, the greatest challenge is in managing complexity. A fairly simple business application can often have anywhere from a few dozen to several hundred code modules, each with several hundred lines of code. In these applications, the best algorithms are simple to understand and easy to implement. To measure complexity, count the number of decision points, function calls, number of variables and the complexity of the data structures.

    • 4

      Compare maintainability. Closely coupled with complexity is maintainability. An algorithm with less complexity, presented with plenty of white space and liberally sprinkled with well-written comments, will be much easier to modify when requirements change. Most developers spend far more time maintaining and modifying existing code than they do creating new software.

    • 5

      Validate for correctness. Often overlooked in a discussion of algorithms is the need for an appropriate algorithm that meets all requirements and works correctly. The code must return accurate results for inputs including boundary conditions and unexpected values. Filters must be in place to reject bad data, and exception handling code must respond to numeric overflows, underflows, network failures or other conditions.

    • 6

      Choose the most appropriate algorithm. The best choice balances all of these factors in a way that maximizes performance while minimizing cost of development and ownership.

Tips & Warnings

  • When possible, use existing code. The C++ libraries, Java class library and the .Net framework include thousands of classes and methods already optimized for performance.

Related Searches:

References

Comments

Related Ads

Featured