Program runs faster than expected - optimization of the compiler/DURATION?

Here is the code example:

Public Shared Sub main (String [] args) {}
int var = 0;
Start long = System.currentTimeMillis ();
for (int i = 0; i < 1000000; i ++) {}
for (int y = 0; y < 1000000; y ++) {}
var = i + y;
System.out.println ("operation took" + (System.currentTimeMillis () - start));
System.out.Print (var);

And the output is:

Operation took 10

So, it took only 10 milliseconds to run 1000000 * 1000000 additions.
Question: is Java not actually perform additions or my expectations is just too old fashioned and it's normal "timing" on modern machines?

Thank you

Valery_Cherepanov wrote:
After a few tests and calculations I now tend to think that java is actually down additions

No it's not "drop" anything. The Hotspot compiler figures simply noted that this:

    for (int y = 0; y < 1000000; y++)
        var = i + y;

is exactly equivalent to this:

   var = i + ;

And then he made similar optimization for the outer loop.

It's just an optimization compiler do what does a compiler optimization: optimization of your microbenchmark down to nothing.

(And looking at the byte-code is not particularly for education, as optimization happens in Hotspot, not in javac.) Access point can do things like inline method that javac cannot do so many things, so most of the optimizations are implemented in Hotspot rather than javac.)

Tags: Java

Similar Questions

  • Loudness Radar can run faster than real time?

    My apologies if this has been asked before - I couldn't find an answer to a search.

    Loudness Radar can run faster than real time? Making sure that my levels is ready for dissemination of a television show, I'll have to essentially play through the whole thing to get a global level. Is it possible to have the Loudness Radar go on and give me a general level without having to hit 'play' and go away for a while? I'd like to be able to do in the first, but I'm fine with the export of hearing if that's what it takes.

    I've never had a problem with just dropping the main level (make sure that the Loudness Radar is set to post fader, btw). So in your example, Yes, I turn down the master by 0.9db.

    Speaking of which, my new faster way to manage the volume on the content of the longer emissions must export just the audio format .wav temporary somewhere, then load this file in hearing and its volume tool to know the LKFS level. Then, I take whatever number I get and set the main volume in first to do no matter what level the station/deaf network/tv customer needs. It's a heck of a lot faster, since the hearing can analyze loudness faster than real-time. On 30 seconds, commercials, using the Loudness Radar in Premiere Pro's no big deal, but dealing with half-hour TV series, with the help of hearing on export to .wav is much faster.

  • How can I leave the program runs longer than the duration of sleep?

    I have a desktop Pavilion Elite HPE - 110 t (win7) .  Turn off display & sleep have the default value (10 & 20 minutes).  According to the instructions that I read (somewhere in the paper documentation) when I got to the computer a few months ago, I do not turn off it during the night.  I think included grounds for diagnostics to run (by default grid) & I "think" I've seen (the next day) scans messages, updates, etc. have been executed.  I however turn off my modem to prevent the activity internet auto (anyway) during the night.

    This configuration has been satisfactory until this morning, when I tried to leave an app running I knew would require more than one hour to complete.  I had other non-computer tasks to do & did not sit the computer baby to keep him awake.  In fact, I thought that 'activity' (including the activities of memory without keyboard activity) he would keep awake.

    To my surprise when I got home 3 hours later, treatment stopped about 45 minutes after the start.  This was determined by the timestamps of the output files.  Normal processing resumed after that I have he awakened from his sleep.

    Is there a way (outside change go-to-sleep time setting each time) to allow work of long-term programs/application to keep running & to go to sleep after the treatment is finished? Am I wrong to think that 'auto diagnostic' are running when the computer & I sleep at night?

    Thank you

    The process will continue even after the monitor goes to sleep.

    I first noticed this problem when you make copies of images hard drive hard drive.

  • Satellite A300D-17F runs slower than expected

    Satellite A300D-17 F

    Hi friends

    Since I bought this machine, I am not happy.
    There is a problem: he works so slow than other laptops and they have inferior properties.
    I don't understand.

    I almost have to break. I've done all the tips (uninstall tempro, stop the backround programs, program viruses... etc) but it's the same.
    -J' I want to listen to an mp3 that is not open for ten seconds, watch the movie it is not open again for 9 to 10 seconds.
    -i wana to connect to a site web it freezes
    -for example the search for Messenger is taking once again for secondssssss
    -implementation of xp, it is hourssss
    but the machines of my friends who have inferior properties are so fast

    Is there someone has this machines? It has the same problems? or only I have these problems?

    Thank you very much right now.

    Hi mate

    > Configuration of xp, it is hourssss
    This means that you have tested the laptop under Win XP?

    How did you install the Win XP? Have you installed using AHCI mode (in BIOS) or you switch to compatible mode?

    By using the compatibility mode that HARD drive could run slower and this could affect the performance of the operating system.

    Solution: You must install the Win XP in AHCI mode. I think the laptop supports the AMD chipset and the required drivers are therefore part of the ATI graphics chip.
    Download the graphics driver, choose the drivers SATA and include it in the Win XP disc using nLite application. nLite is free and all details can be found in the internet.

  • Windows Essentials program running "Real-time Protection"... the mouse cursor turns into hourglass several times per second...

    I have disable real-time protection it stops on and off an hourglass toggleing... its annoying... How to stop to turn to an hourglass without disabling protection... it doesn't seem to be a problem of performance... but it is visually annoying... Please and thank you for your comments.

    I had just installed Microsoft Essentials... before uninstalling software anti-virus TrenMicro expired... maybe Detailer left some files on my system after uninstall?


    This problem normally occurs when there are files that are infected by viruses.

    Method 1:

    Run a scan antivirus on your computer.

    Note: If infections are detected during the scan, there is a risk of data loss because infected files will be deleted.

    Method 2:

    You also try to run the uninstaller to complete tool to remove traces of antivirus Trend.

    Check the issue.

    Method 3: Clean boot

    If the problem persists, you can place the computer in a clean boot.

    Put the computer in a State of boot is a way to know which application is causing this problem.

    To help resolve the error and other messages, you can start Windows by using a minimal set of drivers and startup programs. This type of boot is known as a "clean boot". A clean boot helps eliminate software conflicts.

    Put your boot system helps determine if third-party applications or startup items are causing the problem. If so, you need to maybe contact the manufacturer of the program for updates or uninstall and reinstall the program.

    Step 1: Follow the steps in the link below to do the same thing:

    How to configure Windows XP to start in a "clean boot" State

    Note: After troubleshooting, be sure to set the computer to start as usual as shown here:

    Step 2: To configure Windows to use a Normal startup state

    After you have used the boot is a way to solve your problem, you can follow these steps to configure Windows XP to start normally.

    a. Click Start and then click Run.

    b. type msconfig and click OK. The System Configuration Utility dialog box appears.

    c. click on the general tab, click Normal Startup - load all services and device drivers and then click OK.

    d. When you are prompted, click on restart to restart the computer.

    Hope this information helps. Response with status so that we can help you.

  • Application failed (MFC) in the release through the optimization of the compiler, but works well in the debug version

    I am facing problem with the Release version. Application works fine in the Debug version, but in the Release version a pointer initialized to contain the object of another class becomes allocation to different addresses, causing corruption to its values.

    My main application class is K32App
    code in K32App.h file
    CSheetPrintManager* m_pSheetPrintManager;
    CSheetPrintManager* GetSheetPrintManager() { return m_pSheetPrintManager; }
    In file K32App.cpp
      m_pSheetPrintManager= NULL;
    BOOL K32App::InitInstance()
        m_pSheetPrintManager= new CSheetPrintManager();
     In my file  CSheetPrintManager.cpp
     void CSheetPrintManager::CSheetPrintManager()
       //Initialized all member variables to default values.
     void CSheetPrintManager::Init()
       m_nSheetType = SheetIllegalNone;  //long
       m_sBankEntry.Empty();         //CString
       m_bHistorical = FALSE;        //BOOL
       m_bDebitDetailsSet = FALSE;  //BOOL
       m_mapRequested.RemoveAll(); // Type CMap

    During the startup of the application, when it reaches

        CSheetPrintManager= new CSheetPrintManager();

    and trying to create a m_pSheetPrintManager object, a 'this' inside the CSheetPrintManager.cpp pointer shows a valid address (0x03768ce0) at the stop just to brace {, once I more in CSheetPrintManager.Init (), not 'this' gets different location and starting point to a different address (0 x 0000000) and then passing more its starting pointing to an another rental (0x03786ce0)} ", then arriving to m_mapRequested.RemoveAll(); 'this' points to some other location. back to main application C32App.cpp file I get next to 'm_pSheetPrintManager' error CXX0030 ' expression cannot be evaluated" in the window of the car. and application continues to run. See what get when move mouse m_pSheetPrintManager (can't post the image because need 10 reputation for him :) so antisocial)Auto window studio screenshot 

    In debug mode, I get m_pSheetPrintManager pointing to the same location during all the processing of the application and members are always correctly initialized.

    But in Release mode, m_pSheetPrintManager continues to point to the different location (address in the window of Auto value). and all the class member variables CSheetPrintManager garbage (Uninitialized) values with each line of treatment within the CSheetPrintManager class.

    If I disable the optimization of the c++ in Release Mode then it works very well without any problems.

    Any help/advice/suggestion is the most popular. Thanks in advance.

    PS: This is my first question here so please excuse if you lack something to point or express properly.

    This issue is beyond the scope of this site (for consumers) and to be sure, you get the best (and fastest) reply, we have to ask either on Technet (for IT Pro) or MSDN (for developers)
  • What can I do if the script runs faster than the network?

    I wrote a script between applications moving to InDesign, where he begins to AppleScript, to Photoshop, which AppleScript runs a JavaScript script to perform various tasks.

    It works beautifully on my laptop at home where I do my development. Yesterday, using me as a Guinea pig, I tried it in the office.

    On the third round, I was horrified to see the ExtendScript Toolkit pop up with an error message (about as welcome to see an AppleScript script, asking the user to open the Script Editor and fix a script).

    The error message was that app.bringToFront (); was not a valid function.

    This was the case in InDesign, which has a different activation function, and I realized that, even if my AppleScript called Photoshop activate, I was still in InDesign.

    The app.bringToFront JavaScript was so called because I had joined my code in the model of Tranberry.

    So I pressed the button stop on ExtendScript, returned to InDesign and represented the script. This time he worked as usual.

    Occasionally on our network we spend some time beachball - watch as a communication happens in the background. So I guess the time wherever the error was thrown was on one of these downturns in the network.

    The passage of InDesign, Photoshop is not happening pretty fast, but the script has run and has issued an order Photoshop JavaScript while I was still in InDesign.

    In AppleScript this unhappy communication with users can be avoided using blocks '... try error'.

    Is there an equivalent of the error handling in JavaScript that would allow me to avoid being tossed in the ExtendScript Toolkit and give them a friendly message to apologize, explaining what had happened and inviting them to try again?

    JavaScript has try/catch blocks

    try {}

    app.bringToFront ();

    } catch (e) {}

    error handling code


    Or you might be able to use an if statement

    If (app == 'photoshop') {}

    app.bringToFront ();

    } else {}

    app handle not photoshop


  • Why is the 'UNION' statement faster than 'OR' sometimes?

    Many articles say that the 'UNION' statement can make the SQL statement run faster than "GOLD" awhile. However, why is the 'UNION' statement faster than 'OR' some time? Why does CBO sometimes choose 'UNION', not 'GOLD'.


    If you have a select statement like this

    Select * from my_table where col1 like "something %' or col2 like '% else';"

    and there is an index on col1 and an index on col2. It may be a good idea to chosse a union. This is just an example.

    Best regards


  • faster than El Capitan Windows 10


    I have a 13 "mid-2013 Macbook Air 128SSD / 8 GB/Intel i5.

    I tried the two El Capitan and Windows (via Bootcamp) 10 and Windows runs faster than Mac for a reason any.

    Launching applications faster and overall, it feels snappier and more responsive.

    How is it possible that Windows can run faster on my Macbook as the own Apple operating system?

    Systems running different programs using different device drivers. 'Feel' is a very subjective measure. My windows running in Boot Camp "feels" faster than Windows running on a Windows PC. My El Capitan "feels" faster than my Windows running in Boot Camp 10.

  • How can I be faster than milliseconds on windows 7?


    I'm using Labview 2011 SP1 on windows 7 32bits. I encounter something strange that I can't explain. My program run so fast that I do not understand why?

    In my program, a while loop runs more than 1000000 times during the approximativley. 2500ms I thought that, under windows, time unit was ms and us under RTOS.

    Can someone help me understand what happened here?

    Thank you

  • How can I make my computer run faster

    How can I make my computer run faster than a snail?

    Some tips to speed up your PC can be found here: .

  • HP G32 white screen with all LEDS blink and CPU fan run fast

    Hi all

    I have a laptop HP G32-205TX

    I had a problem that was the device would be loop at startup without showing the start of message or HP logo.

    I changed the Ram memmory and it was fixed.

    Now I'm having a different problem some kind.
    Specifications stopped loop at startup but has all its flashing LED (Caps Lock, Wifi, Lan and the side LED)

    Please, someone help me.

    Thank you

    Hello @Khushal17,

    Welcome to the HP Forums, I hope you enjoy your experience! To help you get the most out of the Forums of HP, I would like to draw your attention to the Guide of the Forums HP first time here? Learn how to publish and more.

    I understand that your laptop fan is running faster than normal and that all lights are flashing. I'd love to help you in this case!

    As a fan of hyperactivity is symptomatic of internal overheating, I recommend that you follow the steps described in this document on the reduction of heat inside the PC to avoid overheating. I also suggest to take a look at this resource: computer does not start and the lights blink or computer beeps, to determine the reason behind the blinking light caps lock.

    If the CAPS LOCK flashing indicates a hardware problem, or the fan continues to run at high speed, please call our technical support at the 800-474-6836. If you do not live in the United States / Canada region, please click the link below to get help from your region number.

    I hope this helps!


  • I have an Imac - route Safari super, super slow.  Google Chrome fast? - why Safari can't run fast

    I have an Imac - route Safari super, super slow.  Google Chrome fast? - why Safari can't run fast

    Try to reset the settings of Safari:

    1. open Safari

    2. click on the Safari menu at the top (to the right of the Apple logo)

    3. Select the Preferences/Privacy tab

    4. click on remove all data from the Web site

    5. close Safari.

    Remove cache Safari files:

    1. click on finder

    2. look for the menu GO to top

    3. click on GO and hold down the option key. This will show a user library folder.

    4. click library and find the Caches folder

    5. in the folder caches Ouvrezledossier

    6. move the Cache.db file Trash.

    This should solve the problem. If it does not help, try to disable the Safari extensions

    1. open Safari

    2. click on the Safari menu at the top (to the right of the Apple logo)

    3. Select Preferences

    4. find the Extensions tab

    5 disable all extensions of

    6. relaunch Safari

  • "A script already works" as he tried to run more than one item

    We recently move to ODT Since then, attempt to run more than one element of the Solution Explorer (by selecting the items, right click and select 'Run') results in an error popup "Oracle Developer Tools. A script is already ongoing enforcement." If multiple items are selected, it translates into many error messages and some of the random elements are actually executed on the server. Also, choose ' run on ' are now asking him to specify the target database for each selected element (as opposed to once for all selected items as it was). All this for good work in the previous version we were using. Anyone encountered this? All the patches? We used to use the multiple selection and 'Run' or ' run on ' to deploy several items at once, but it works more - doing either at a plant in time, but if you have hundreds of items to launch, it becomes quickly unusable.

    Thanks for any idea.


    Good news! I was told that this will be fixed in our 12.1 release ODAC (our next version). Thanks for reporting this to us.

    Be sure to check our beta 2 (available), which includes the schema comparison. We create scripts of diff (one or a master with child scripts, one for each schema object). It may be helpful to you and we would like your comments as appropriate.

  • iTunes update errors with the following message appears: there is a problem with this Windows Installer package. A program run as part of the set up did not complete as expected.

    iTunes error update

    I am trying to install an update to iTunes on my laptop and find the folowing part-way through the installation error:

    "There is a problem with this Windows Installer package. A program run as part of the set up did not complete as expected. Contact your provider to support personal or package. »

    I got iTunes for 3-4 years now and have always been able to install updates successfully, so don't not sure what is the problem.

    I tried msconfig and changed the boot process, so it includes all of the non-Windows elements, as suggested on the Microsoft Web site, but that has not worked.

    Can anyone help?

    Thank you

    The instructions were to contact the vendor of the package. This isn't iTunes, Microsoft.

    Ask the question in the Apple Forums:

Maybe you are looking for