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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:41:03+00:00 2026-05-31T11:41:03+00:00

This is not the first time I’ve had problems with clock times in a

  • 0

This is not the first time I’ve had problems with clock times in a programming language. Basically I’m measuring how fast a function is running by calling it in a while loop. Problem is that for some reason the elapsed time keeps getting shorter the longer the while loop runs. Can anyone explain? Code below.

DescriptiveStatistics stats = new DescriptiveStatistics();
while(true) {
    long startTime = System.nanoTime();
    executeSaxonXsltTransformation();
    long stopTime = System.nanoTime();
    long elapsedTime = stopTime-startTime;
    stats.addValue((double)elapsedTime);
    System.out.println(stats.getN()+" - "+elapsedTime+ " - "+stats.getMean());
}

So after about 1,000 runs the elapsed time is 750k to 850k. But after about 100,000 runs the elapsed time drops to 580k to 750k. The continual decrease is best noticed by watching the average (stats.getMeans()), which after 108k loops has an average of ~632k compared to 3k loops with an average of ~1million. Switching to currentTimeMillis instead of nanoTime doesn’t change anything.

  • 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-31T11:41:04+00:00Added an answer on May 31, 2026 at 11:41 am

    This is totally supposed to happen, because Java’s JIT optimizes code that gets run extensively — the more it’s run, the more effort the JIT puts into optimizing it.

    If you’re trying to benchmark, you should “warm up” the benchmark by running the method for a few seconds without timing, and only then start doing timing. Alternately, you could use a library that knows how to do consistent benchmarking in Java — warming up the JIT, getting accurate measurements whether your method takes nanoseconds or seconds — like Caliper.

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

Sidebar

Related Questions

Okay, so this is not the first time I've had this problem, but it
This question might not seem programming related at first, but let me explain. I'm
It's not the first time I'm having this problem, and it's really bugging me.
This is not the first time I have used databases using the C# in
No idea why this is not working. It's the first time I am working
Well, I'm sure this is not the first time to see this question. and
This is my first time using git, and I am not sure what is
Can't figure out why this is not working. First time using :has_many => :through
I have a rather bizarre situation, and it's not the first time I this
This is not the first time I am working with ajax and such, I

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.