Ahmdal’s Law



We need to bear in mind the Ahmdal’s Law when doing code optimisation.

amdahl Ahmdal's Law general parallel computing

amdah law

The speed up can be described in the following equation:

Speedup = time_old /time_new

tex_8af6284ef0c4b04af487a889ec3d21f7 Ahmdal's Law general parallel computing

Where, the func_cost (notation c) is the percentage of the program runtime used by the function func, and func_speedup (notation by s) is the factor by which you speedup the function.

For example, if you optimize a function foo(), which is 40% of the runtime, so that it runs as twice as faster, your overall application will run 25% faster based on the above equation:

tex_18baca3d9a80c81fa67e4c145aae51d9 Ahmdal's Law general parallel computing

This means infrequently used code (e.g., the scene preparation) should be optimized little (or avoided if possible). This is often quoted as: “make the common case fast and the rare case correct.”

Ahmdal’s Law by Javascript Implementation

Let’s compute some values and we choose Javascript to implement this equation:

1
2
3
var ahmdal_law = function(c, s) {
  return 1.0 / (1 - c + c / s);
}
var ahmdal_law = function(c, s) {
  return 1.0 / (1 - c + c / s);
}

Let’s assume that s = 2 (two times faster) and

1
2
3
for (var p = 0.1; p <= 1.0; p += 0.1) {
    console.log(p + ", " + speedup(p, 2));
}
for (var p = 0.1; p <= 1.0; p += 0.1) {
    console.log(p + ", " + speedup(p, 2));
}

And we can obtain the rough overall speed-up gains:

1.05, 1.11, 1.17, 1.25, 1.33, 1.42, 1.53, 1.66, 1.81 and 2.

Visualization of Ahmdal’s Law

The following shows the graphical representation of the speed-ups versus. the number of processors (N times faster), if the overhead (data transfer) is not considered.

Amdahl_Law Ahmdal's Law general parallel computing

Amdahl_Law Speed up v.s. Number of Processors

And the following helps understand the fact that, we need to spend most resources in speed up the most performance critical parts, in order to achieve a greater overall performance gain.

amdahl-law-faster Ahmdal's Law general parallel computing

amdahl-law-faster

–EOF (Coding For Speed) —

GD Star Rating
loading...
501 words Last Post: Simple C++ Coding Exercise - Use Lookup Table to Eliminate the Condition Checks
Next Post: Which is Faster? VBScript or JScript on WSH - A Performance Comparison using Sieve of Eratosthenes

The Permanent URL is: Ahmdal’s Law (AMP Version)

Leave a Reply