The importance of not wasting resources

In my table clock application there was a sort of infinite-loop. There, Python was looping as quickly as possible, gobbling up processor cycles for no good reason (see Figure 1).

Figure 1. 25 % of a QuadCore wasted in reading current time.

Figure 1. 25 % of a QuadCore wasted in reading current time.

To prevent Python from dilapidating processor cycles, the time.sleep() command tells the interpreter to suspend processing for the specified number of seconds, 0.98 in this case. If we look at Figure 2 we can observe that it makes quite a difference.

Figure 2. Optimized script.

Figure 2. Optimized script.

Take a look at the revisited code in GitHub Gist.