Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9150157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:34:31+00:00 2026-06-17T11:34:31+00:00

I was working with some paralization and that brought me looking into Amdahl’s law.

  • 0

I was working with some paralization and that brought me looking into Amdahl’s law. I’ve read a number of posts on the topic;

Calculate performance gains using Amdahl's Law

How to calculate Amadahl's Law for threading effectiveness

http://en.wikipedia.org/wiki/Amdahl%27s_law

…but was hoping to find a C# example showing it in practice. Searching has proved no results. In theory it should be possible to make a serial application, time the parallelisable parts, run a parallelised version, recording the length it takes the parallel parts and compare the difference (knowing how many processors are being used) to the result of Amdahl’s function. Is this correct and is anyone aware of such an example existing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:34:32+00:00Added an answer on June 17, 2026 at 11:34 am

    Note: A complete working downloadable version of the program can be found on My Github Page

    So with Amdahl’s Law, we split the work in to “Work that must run in serial” and “Work that can be parallelized“, so let’s represent those two workloads as List<Action>:

    var serialWorkLoad = new List<Action> { DoHeavyWork, DoHeavyWork };
    var parallelizableWorkLoad = new List<Action> { DoHeavyWork, DoHeavyWork, DoHeavyWork, DoHeavyWork, DoHeavyWork, DoHeavyWork, DoHeavyWork, DoHeavyWork };
    

    Where the DoHeavyWork delegate is abstracted brilliantly as:

    static void DoHeavyWork()
    {
        Thread.Sleep(500);
    }
    

    As you can see I’ve made the parallelizable workload a bit heavier for fun and to make a decent example of it.

    Next we have to run both workloads in Serial to get our baseline:

    var stopwatch = new Stopwatch();
    stopwatch.Start();
    // Run Serial-only batch of work
    foreach (var serialWork in serialWorkLoad)
    {
        serialWork();
    }
    
    var s1 = stopwatch.ElapsedMilliseconds;
    
    // Run parallelizable batch of work in serial to get our baseline
    foreach (var notParallelWork in parallelizableWorkLoad)
    {
        notParallelWork();
    }
    
    stopwatch.Stop();
    var s2 = stopwatch.ElapsedMilliseconds - s1;
    

    At this point we have how long it took each workload to run in serial. Now, let’s run it again, with the parallelizable portion parallelized.

    stopwatch.Reset();
    stopwatch.Start();
    // Run Serial-only batch of work
    foreach (var serialWork in serialWorkLoad)
    {
        serialWork();
    }
    
    var p1 = stopwatch.ElapsedMilliseconds;
    
    // Run parallelizable batch of work in with as many degrees of parallelism as we can
    Parallel.ForEach(parallelizableWorkLoad, (workToDo) => workToDo()); // In Java this is Magic Unicorns
    
    stopwatch.Stop();
    var p2 = stopwatch.ElapsedMilliseconds - p1;
    

    Now that we have the baseline and the parallelized version, we can calculate the speedup and report our findings:

    var speedup = (double)(s1 + s2) / (p1 + p2);
    
    Console.WriteLine("Serial took  : {2}ms, {0}ms for serial work and {1}ms for parallelizable work", s1, s2, s1 + s2);
    Console.WriteLine("Parallel took: {2}ms, {0}ms for serial work and {1}ms for parallelizable work", p1, p2, p1 + p2);
    Console.WriteLine("Speedup was {0:F}x", speedup);
    

    And as Amdahl’s Law tells you, it is hard to scale perfectly with the # of cores you have because of the serial-only work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working some code that inserts csv rows into an SQLite database using Python.
Working on some tweaks for a build script, I noticed that the output from
When working on some Javascript for a web application, I noticed that I had
Working my way through some some Python code, I'm noticing there are a number
I have some working code that I have been using on a test O365
Im working with some legacy code that generates a given message on a webpage
I am working with some VBA code in Access that when a very specific
I was looking for real information about this, I am working some system on
Working on some code today, I found that the following would work in 5.3,
Some working C++ code that I'm porting from Linux to Windows is failing on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.