Run-time efficiency of a Program◀ Memory Footprint▶ Robustness of a Program Amazon
fficiency refers to the running time of a program. Usually the faster the program runs the better. An exception is that if your program runs fast but requires a huge memory footprint then it may not suit the platform you are using. This case is rare; so it usually doesn’t apply.
It usually takes technical knowledge to achieve great efficiency, especially in advanced data structures.
For instance, a binary search tree generally offers greater efficiency than a linear search mechanism such as an array; however, in its worst cases, the binary search tree’s efficiency is no better than the linear method’s. Experienced software engineers may choose to use another data structure such as a balanced binary search tree (e.g. an AVL tree) despite its rather complicated design.
Many data structures have been designed and implemented over the past few decades, and each of them has its advantages and disadvantages.
The design of a program also has a significant impact on its efficiency. It includes the means to store data, the techniques to solve a sub task, the program’s flow control, and so on.
For example suppose your program has a big switch
statement (or alternatively a series of if-else
statements) which simply assigns a variable to some value given some condition. Imagine how many compare, call, jump instructions need to be created when the program is running!
If you use a hash table-like data structure in C++ then you can create a static mapping between keys and values and be able to do this task much faster and much more efficiently! In fact a hash table is one of the most useful data structures!
Another way to increase efficiency of a program is to be familiar with C++ standard library. If you know exactly how its functions are implemented, you know their time complexities.
For example, the containers provided by STL have many operations in common, but they have different time complexities. The deque
template class supports insertion and removal of data items in constant time, whereas vector
takes linear time.
What is your program meant to spend the most time doing? Traversing data? Deleting data? Inserting new data? If you are familiar with the time complexity of each operation of each data structure and with the your program's most common use cases, when it comes time to determining which functions or techniques to use, you will be able to make wise decisions.
As you can see, achieving maximum efficiency of a program basically means you have to know the language extremely well. Many programmers are not too much concerned with the efficiency of a program because they think as long as it works and does not take ridiculously long, it’s fine.
However, if you write a program that handles a humongous set of data or if you are building an enterprise level software application, you will notice the significance of data structure and program design, and thus realize the importance of efficiency.
◀ Memory Footprint▶ Robustness of a Program