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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:02:36+00:00 2026-06-05T03:02:36+00:00

Even though it is good to check performance of code in terms of algorithmic

  • 0

Even though it is good to check performance of code in terms of algorithmic analysis and Big-Oh! notation i wanted to see how much it takes for the code to execute in my PC. I had initialized a List to 9999count and removed even elements out from the them. Sadly the timespan to execute this seems to be 0:0:0. Surprised by the result there must be something wrong in the way i time the execution. Could someone help me time the code correct?

        IList<int> source = new List<int>(100);
        for (int i = 0; i < 9999; i++)
        {
            source.Add(i);
        }

        TimeSpan startTime, duration;
        startTime = Process.GetCurrentProcess().Threads[0].UserProcessorTime;

        RemoveEven(ref source);
        duration = Process.GetCurrentProcess().Threads[0].UserProcessorTime.Subtract(startTime);

        Console.WriteLine(duration.Milliseconds);
        Console.Read();
  • 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-05T03:02:37+00:00Added an answer on June 5, 2026 at 3:02 am

    The most appropriate thing to use there would be Stopwatch – anything involving TimeSpan has nowhere near enough precision for this:

    var watch = Stopwatch.StartNew();
    // something to time
    watch.Stop();
    Console.WriteLine(watch.ElapsedMilliseconds);
    

    However, a modern CPU is very fast, and it would not surprise me if it can remove them in that time. Normally, for timing, you need to repeat an operation a large number of times to get a reasonable measurement.

    Aside: the ref in RemoveEven(ref source) is almost certainly not needed.

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

Sidebar

Related Questions

Even though it is possible to write generic code in C using void pointer(generic
Even though it's not part of HTTP 1.1/RFC2616 webapps that wish to force a
Even though I have a fermi card(gtx 560) I get this error on VS2010:
Even though I've been reading other topics about my kind of problem, I can't
...even though pointers to member functions are strange animals ? I am coding a
Why is it necessary even though everything is specified in a makefile?
One would expect that even though strings are immutable, value-equality and reference-equality would not
In C# you can define delegates anonymously (even though they are nothing more than
I've heard of GAE and even though it doesn't support PHP, people have gotten
I am creating a library and even though it is working perfectly fine by

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.