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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:45:06+00:00 2026-05-31T17:45:06+00:00

See edits below There is no casting going on with the termination check. I

  • 0

See edits below

There is no casting going on with the termination check. I would think the < and the ++ would be as fast with ints and longs on a 64bit machine. But I guess not?

int: 65 milliseconds:

public void testWTF() throws Exception {
    int runs = 10;
    long hs = 0;
    long timeSum = 0;
    for (int run = 0; run < runs; run++) {
        int term = Integer.MAX_VALUE;
        long start = System.currentTimeMillis();
        // ***** loop to be tested ******
        for (int i = 0; i < term; i++) {
            hs++;
        }
        timeSum += (System.currentTimeMillis() - start);
        System.out.println("hs = " + hs);
        hs = 0;

    }
    System.out.println("timeSum = " + timeSum);
    System.out.println("avg time = " + (timeSum / runs) + " for " + runs + " runs");
    System.out.println("hs = " + hs);
}

long: 1445 milliseconds

public void testWTF() throws Exception {
    int runs = 10;
    long hs = 0;
    long timeSum = 0;
    for (int run = 0; run < runs; run++) {
        long term = Integer.MAX_VALUE;
        long start = System.currentTimeMillis();
        // ***** loop to be tested ******
        for (long i = 0; i < term; i++) {
            hs++;
        }
        timeSum += (System.currentTimeMillis() - start);
        System.out.println("hs = " + hs);
        hs = 0;

    }
    System.out.println("timeSum = " + timeSum);
    System.out.println("avg time = " + (timeSum / runs) + " for " + runs + " runs");
    System.out.println("hs = " + hs);
}

hardware: 64-bit Xeon running windows 7 64bit.

edit: I updated this to do several iterations. For 1 million runs with the int version, the average time is 65 milliseconds. The long version takes too long for 1 million, 1000 and even 100. For 10 runs the average time is 1447 milliseconds.

Also, I’m using hs outside the loop so that the loop does not get jitted away.

  • 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-31T17:45:07+00:00Added an answer on May 31, 2026 at 5:45 pm

    This is a very bad/unreliable/unrealistic way of doing benchmarks, since the JIT isn’t really given a chance to do much optimization — you only run the benchmarks once, and you measure the first run.

    Basically, Java’s JIT will optimize your code significantly more once it sees your code getting used extensively. In a real program, the JIT will be optimizing any critical loops, so if you want a benchmark that mimics the real world, you have to convince the JIT to kick in.

    The simplest way to get an accurate benchmark in Java is to use a tool like Caliper that knows how to properly warm up the JIT and get accurate measurements, and then see if the results are more consistent.

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

Sidebar

Related Questions

EDIT 3: Solved. See below. EDIT 2: I think Chadwick's on the right track
EDIT: See my working code in the answers below. In brief: I have a
I have a Controller with two Edit methods (see below). When I submit the
I receive this message (see image below) when I try to edit in debugging.
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
Edit: I have solved this by myself. See my answer below I have set
EDIT: I would really like to see some general discussion about the formats, their
EDIT See my solution below /EDIT I have a Visual Studio solution with two
I am banging my head up against the wall about what I think would
EDIT: jldupont 's suggestion ( see below ) did the trick Window -> Preferences

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.