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 7530577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:56:56+00:00 2026-05-30T04:56:56+00:00

I built a sample program to check the performance of tasks in parallel, with

  • 0

I built a sample program to check the performance of tasks in parallel, with respect to the number of tasks running in parallel.

Few assumptions:
Operation is on thread is independent of another thread, so no synchronization mechanisms between threads are essential.

The idea is to check, whether it is efficient to:
1.Spawn as many tasks as possible
or
2. Restrict the number of tasks in parallel, and wait for some tasks to complete before spawning the remaining tasks.

Following is the program:

    static void Main(string[] args)
    {
        System.IO.StreamWriter writer = new System.IO.StreamWriter("C:\\TimeLogV2.csv");

        SemaphoreSlim availableSlots;


        for (int slots = 10; slots <= 20000; slots += 10)
        {
            availableSlots = new SemaphoreSlim(slots, slots);
            int maxTasks;
            CountdownEvent countDownEvent;
            Stopwatch watch = new Stopwatch();
            watch.Start();

            maxTasks = 20000;
            countDownEvent = new CountdownEvent(maxTasks);

            for (int i = 0; i < maxTasks; i++)
            {
                Console.WriteLine(i);
                Task task = new Task(() => Thread.Sleep(50));
                task.ContinueWith((t) =>
                {

                    availableSlots.Release();
                    countDownEvent.Signal();
                }
                );

                availableSlots.Wait();
                task.Start();
            }
            countDownEvent.Wait();

            watch.Stop();
            writer.WriteLine("{0},{1}", slots, watch.ElapsedMilliseconds);
            Console.WriteLine("{0}:{1}", slots, watch.ElapsedMilliseconds);
        }

        writer.Flush();
        writer.Close();
    }

Here are the results:
enter image description here

The Y-axis is time-taken in milliseconds, X-axis is the number of semaphore slots (refer to above program)

Essentially the trend is: More number of parallel tasks, the better. Now my question is in what conditions, does:

More number of parallel tasks = less optimal (time taken)?

One condition I suppose is that:
The tasks are interdependent, and may have to wait for certain resources to be available.

Have you in any scenario limited the number of parallel tasks?

  • 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-05-30T04:56:57+00:00Added an answer on May 30, 2026 at 4:56 am

    The TPL will control how many threads are running at once – basically you’re just queuing up tasks to be run on those threads. You’re not really running all those tasks in parallel.

    The TPL will use work-stealing queues to make it all as efficient as possible. If you have all the information about what tasks you need to run, you might as well queue them all to start with, rather than trying to micro-manage it yourself. Of course, this will take memory – so that might be a concern, if you have a huge number of tasks.

    I wouldn’t try to artificially break your logical tasks into little bits just to get more tasks, however. You shouldn’t view “more tasks == better” as a general rule.

    (I note that you’re including time taken to write a lot of lines to the console in your measurements, by the way. I’d remove those Console.WriteLine calls and try again – they may well make a big difference.)

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

Sidebar

Related Questions

I've built an iPhone application using the parsing code from the TopSongs sample iPhone
I have built a simple menu in jQuery http://vanquish.websitewelcome.com/~toberua/ Here is a sample of
I am really stumped. I am running delphi 2007 on vista. I have built
// Write a program to check whether or not two arrays are identical in
How can I write a program that will automatically generate a sample examination? For
Recently, I have a try to build and run sample hello world program of
For a sample program, though this is doing all good for me. But I
The app in question is a simple sample program. In my view controller header,
i have written a sample program.below: #include<iostream> #include<string> #include<set> using namespace std; int main()
I've got a simple java program, socket, AWT and jUnit dependencies. I've built it

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.