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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:45:00+00:00 2026-05-30T08:45:00+00:00

I was testing some cases in C# to consider some essentials in performance, While

  • 0

I was testing some cases in C# to consider some essentials in performance,
While i was testing i faced a weird case

 for (int i = 0; i < 30; i++)
 {
     DateTime d = DateTime.Now;
     print();
     result.Add  ((DateTime.Now - d));
 }

 foreach(TimeSpan t in result)
     Console.WriteLine(t.ToString());

while the print function was simply :

public static void print ()
{
     for (int i = 0; i < 10000; i++)
     {
         Console.WriteLine( string.Format("{0}", i));       
     }
}

i was shocked with the results while the first three loops it took about 5 seconds while after that it took about 0.5 sec.
Here is some :

00:00:05.6212696
00:00:05.6072002
00:00:05.5837965
00:00:01.9451673
00:00:00.5526335
00:00:00.5540554
00:00:00.5676418
00:00:00.5372442
00:00:00.5772550

i just want to know why it got better by almost 10 times after the third iteration?

  • 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-30T08:45:02+00:00Added an answer on May 30, 2026 at 8:45 am

    I just run the same code in my PC and got the following output:

    00:00:00.0469083
    00:00:00.0312722
    00:00:00.0312722
    00:00:00.0469083
    00:00:00.0312722
    00:00:00.0312722
    00:00:00.0312722
    00:00:00.0469083
    
    ....
    

    As you see there is no notable difference. I would suggest, first do not loose the time on
    checking the performance for these kind of cases, as it can vary from PC to PC, and repeat suggession of Jon, to use StopWatch, for more accurate measurment.

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

Sidebar

Related Questions

I would like to setup some automated testing of test cases upon Fortran binaries
I am testing some weird-looking CSS code that I wrote (I'm using a mix
I am testing some db layer functions. In one, I am simulating the user
Hi I'm testing some CRUD operations in Nhibernate. I have 3 tests in this
I've testing some new CLR 4.0 behavior in method inlining (cross-assembly inlining) and found
I have some concerns related to the fact of testing some functions containing the
I have just started out with testing some php mvc framework In it, it
I'm looking at using the Dojo Objective Harness (DOH) for testing some custom JavaScript
I have a ASP.NET MVC site using Membership Provider. I have trouble testing some
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }

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.