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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:42:11+00:00 2026-05-26T05:42:11+00:00

A single threaded program running a loop of 500 million iterations takes usually about

  • 0

A single threaded program running a loop of 500 million iterations takes usually about 400 ms and occasionally about 1200 ms on a 2.8 GHz linux computer. This is observed in a program that does nothing else but measure the elapsed time of the loop. What accounts for this variability?

import java.io.PrintWriter;
import java.util.Date;

public class Tester
{
    public static void main(String[] args)
    {
        PrintWriter pw = new PrintWriter(System.out, true);

        Date d0 = new Date();
        long t0 = d0.getTime();

        for (long i = 0; i < 500000000; i++)
            ;

        Date d1 = new Date();
        long t1 = d1.getTime();

        pw.format("%d\n", t1 - t0);   
    }
}
  • 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-26T05:42:11+00:00Added an answer on May 26, 2026 at 5:42 am

    The garbage collections routines need to run some time, even if you don’t have garbage to collect.

    It is easy to assume that since you don’t allocate or dereference memory then you will not need to collect garbage; however, the garbage collection routine is running in an independent thread and does not inspect the possible flows through your code to determine if it should run.

    So, the garbage collection routine launches and finds no garbage to collect. That takes some time.

    In addition, your program (that is, the entire JVM interpreting your classes) may have been swapped off the CPU by the operating system’s need to immediately handle some interrupt. This can even happen in multi-core systems, depending on the CPU’s core selection algorithms. Examples of items that the CPU must handle immediately include copying Ethernet memory buffers into system memory (to prevent dropped packets), capturing keyboard input, etc.

    In short, if you want your analysis to mean something, you have to do real statistics on your benchmarking, as all sorts of external items can impact your running program’s time.

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

Sidebar

Related Questions

When I run a single-threaded program that i have written on my quad core
I'm writing a single threaded program, which sometimes calls blocking methods (ie process.waitFor ).
I am working on a program which is essentially single-threaded, and its only thread
I run a very simple, single-threaded java program. When I check the threads using
I am working on a Windows program which is completely single-threaded and has no
Seeing as how node is single threaded, If I have node server running on
Suppose I have a function in a single threaded program that looks like this
I have an single threaded, embedded application that allocates and deallocates lots and lots
I normally work on single threaded applications and have generally never really bothered with
I have worked on single threaded business logic/back-end programming for most of my career.

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.