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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:04:46+00:00 2026-06-03T12:04:46+00:00

I am running some experiments, timing them and comparing the times to find the

  • 0

I am running some experiments, timing them and comparing the times to find the best “algorithm”. The question that came up was if running the tasks in parallel would make the relative runningtimes of the experiments wrong and if I would get more representative results by running them sequentially. Here is a (simplified) version of the code:

public static void RunExperient(IEnumerable<Action> experiments)
    {
        Parallel.ForEach(experiments, experiment =>
        {
            var sw = Stopwatch.StartNew(); //line 1
            experiment();                  //line 2   
            sw.Stop();                     //line 3
            Console.WriteLine(@"Time was {0}", sw.ElapsedMilliseconds);
        });
    }

My questions are about what is happening “behind the scenes”:

  1. When a task has started, is it possible that the OS or the framework can suspend the task during its execution and continue on later making the running time of the experiment all wrong?

  2. Would I get more representative results by running the experiments sequentially?

  • 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-03T12:04:48+00:00Added an answer on June 3, 2026 at 12:04 pm

    That depends on the machine that you are running on and what the experiments do, but generally the answer is yes, they may affect one another. Mainly through resource starvation. Here’s an example:

    public class Piggy { 
       public void GreedyExperiment() { 
           Thread.Priority = ThreadPriority.Highest;
           for (var i=0;i<1000000000;i++) {
               var j = Math.Sqrt(i / 5);
           }
       }
    }
    

    That’s going to do a tight loop on a high priority thread, which will basically consume one processor until it is done. If you only have one processor in the machine and TPL decides to schedule two experiments on it, the other one is going to be starved for CPU time.

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

Sidebar

Related Questions

I'm running some experiments in WebGL, one of them being an XOR effect fragment
When running some tests I came across the following issue. When using: private String
I was running some code that did a printout in a swingworker. I was
i've been running some experiments of my own with Spring Roo and it seems
I'm writing a script that makes some trivial changes and then commits them to
I've just been running some simple debug tests against arrays, and noticed that when
Question I am running a bit of an experiment and could use some help.
I am running some experiments with I/O intensive applications and am trying to understand
I am running some experiments using a Java program including Hibernate data storage. An
I have some long-running CLI PHP scripts that run regularly via cron. I'd like

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.