Power Usage of Algorithms in C#

Algorithms power the world – from search to streaming to AI. Each algorithmic domain has a variety of algorithms to choose from, with different run times and characteristics. But how much power do algorithms use? Does power usage vary between algorithms? Are some algorithms more power efficient than others?

This blog answers these questions by exploring a few sequential (single-core) algorithms and their power usage. Power Usage of Parallel Algorithms in C# explores the same for parallel algorithms.

Power Measurement Setup

Dell Alienware laptop is used, with Intel 12th Gen i7-12700H processor (20 core) and 64 GB of system memory, running Windows 11 operating system. SURAIELEC Energy watt meter (Model: UPWMA02A) is the measurement device.

This meter is plugged into power, while the laptop is plugged into the meter. In real time, it shows the voltage and current, while computing wattage for convenience.

Power usage of each algorithms was obtained by running each algorithm repeatedly many times with a large input array, again and again. During these numerous runs, the wattage meter reading range was recorded. The baseline power level was about 45 watts, with only the Command Prompt window running and the laptop not in a low power state.

Sorting

An array of 200 million 32-bit unsigned integers filled with random values is the input to all sorting algorithms, to avoid any caching effects.

AlgorithmPerformance OrderPerformancePower
Array.SortNlgN12 – 1328 – 30
Merge SortNlgN8 – 828 – 33
LSD Radix SortN132 – 15130 – 34

Performance units are millions of unsigned integers per second. Power units are watts, which show power in addition to the baseline power level of about 45 watts.

All sequential (single core) sorting algorithms use nearly the same amount of power. The LSD Radix Sort algorithm has the highest performance and is the most power efficient. It is more than 10X higher in performance than C# standard Array.Sort, along with more than 10X higher in power efficiency. For the same power, it can sort 10X more data. Or, it can sort the same amount of data using 1/10-th the amount of power. It sorts 4.4 million 32-bit unsigned integers per watt using a single core of the processor.

Summation

In the works…

Copy

In the works…

Leave a comment