How can I get accurately the execution time of a method?

My first idea is:
long start =System.currentTimeMillis();
method call
long end =System.currentTimeMillis();
long executionTime= end-start;
I know this is a very trivial wat, I have not always the same accuracy with execution of the same method.
Do you have better idea to solve it?

Simple answer: you can't. Basically and in general because there always will be other threads running on your computer, be they java threads or other (native) threads.
But with java there is another problem as well. Your JVM might decide to compile your byte code into native code, thus giving different run time results.
What is generally done when someone needs an estimate of the runtime of some java method is to follow the following steps:
1) Run the method a considerable number of times to alert the JVM that it might benefit from compiling byte code to native code.
2) Give the JVM some rest by invoking sleep for some time. It may use that rest to do the compilation.
3) Run the method again a couple of times and calculate the average runtime.
This will give you some idea, when you have alternative implementations, what implementation is most efficient.
I'm fullly aware that this is not scientific, but it helps me sometimes,
Piet

Similar Messages

  • When creating a book how can I get all the photos from an album to show up in the order they were in the album?

    When creating a book in iphoto, how can I get all the photos from the album I want to use to show up in the order that they are in the album?  When I tried to use the option to add my own photos instead of having the program "flow" them, they showed up all mixed up.

    iPhoto puts them in the book in chronological order.  So to get your photos from an album into an iPhoto book in the same order you will need to use the Photos ➙ Batch Change ➙ Date menu option and set them all to the same date with a 1 minute time difference between each. 
    OT

  • How can i use in the same time input line and mic to recorder in several track whit SONAR

    I have beem recording only input line because SONAR 4 not recognized the mic in, Help me!!!.
    Thank you. Sorry for my english

    LIMACAR wrote:
    How can i use in the same time input line and mic to recorder in several track whit SONAR 4. I have beem recording only input line because SONAR 4 not recognized the mic in, Help me!!!.
    Thank you. Sorry for my english
    Depending on which soundcard you have there, but if your card is capable for
    ASIO -> activate I/O drivers on Sonar/Options/Audio/Drivers -tab (mic/line sources should be listed there --> activate) and select the mic or/and Line sources on tracks "I" - dialog
    WDM/KS -> use the Surround Mixer or windows recording controls for recording source selection (mic should be listed there)
    MME32 - > same w/ WDM/KS
    If you use Asio4All --> same w/ WDM/KS & MME32
    No mic and line source simultaenously w/ WDM/KS and MME32.
    You perhaps be able to do this w/ kX drivers.
    jutapa
    ADDED:
    You can also install modded version of Audigy 2 drivers/software but I have never done this w/ Li've! 5. so I can't be sure if you get ASIO support for your card.
    Here are the instruction --> http://www.tech-pc.co.uk/audigy-2.php
    jutapaMessage Edited by jutapa on 05-25-2006 02:48 PM

  • How can I get extract the data between two cursors on an XY graph

    How can I get extract the data between two cursors on an XY graph

    Well, you say xy graph, so this might be a more complicated problem.
    For a waveform graph it's trivial. Simply get the two cursor indices (property: cursor index) and apply them to array subset of the data. Is that all you need?
    Here's how the above code would look like. using cursor.index instead of cursor.x elimnates the need to include scaling information.
    For an xy graph, there could be multiple segments (e.g. imagine a spiral that passes the desired x range multiple times from both sides). This would neeed significantly more code for a general solution.
    Message Edited by altenbach on 11-24-2009 07:53 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    cursorsubset.png ‏17 KB

  • HT201401 cannot open the menu and cannot even turn it off, the white apple image is displayed on the screen. how can i get into the menu?

    cannot open the menu and cannot even turn it off, the white apple image is displayed on the screen. how can i get into the menu?

    Hold down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple logo appears - ignore the red slider.

  • I have paid for ipages 09 on 15/05 but never succed to enter the serial code. After 45 days, altough I was charged by 20 chf, I cannot completely use all ipages tools(impossible to save ). How can I get again the serial code I paid for?

    i have paid for ipages 09 on 15/05 but never succed to enter the serial code. After 45 days, altough I was charged by 20 chf, I cannot completely use all ipages tools(impossible to save ). How can I get again the serial code I paid for?

    Getting the request for a serial number means that at some time you had the iWork ’09 trial installed. You need to delete the trial & then reinstall from the boxed DVD or the Mac App Store. The files to delete are the iWork ’09 folder from the main HD > Applications; the iWork ’09 folder in HD > Library > Application Support & the individual iWork application plist files found in HD > Users > (your account) > Library > Preferences for each user. The easiest way to fix the problem is to use Yvan Koenig's AppleScript that removes the files. You can find it on his box.com account in for_iWork'09 > other_iWork'09 items > uninstall iWork '09.zip. Download uninstall iWork '09.zip, decompress it, open it in AppleScript Editor and click the Run button.
    Apple's support article on the subject says it's due to having a copy of the trial that is a higher version that the one you've purchased, but I'm not sure that is very common. This problem started with Snow Leopard & it seems to be some code in the iWork installers that doesn't do what it should.

  • How can i get back the adobe creative cloud shared folder after I deleting it?

    How can i get back the adobe creative cloud shared folder after I deleting it?

    I think Adobe pulled the Creative Connect Desktop app until the new CC release next month. I just built a new PC and noticed it wasn't available in the app manager any more. On my other machines it isn't working anyway. In another post Adobe devs said they new it was down because thay were working out some server issues. It looks like they couldn't resolve them.
    I bought into the CC right from the beginning since I never buy my software outright but rather use a credit card. I thought that getting the whole master suite for $30 a month interest free was a great deal. Having all the software has been great, but it was over a year before we even saw a desktop syncing folder and noe it seens as though we are going to have server problems every time they upgrade the cloud leaving us to have to use the cluncky web interface during these sync blackouts.
    I can tell you Adobe better get it together cause ther starting to p*ss off a lot of loyal customers. It feels like were dealing with a cellphone company who only gives deals to the new customers and once you've signed the contract your screwed.
    Here is the link to whats going on
    Announcement: Creative Cloud file sync service offline (Updated)
    Hide Details
    The Creative Cloud Connection preview is currently offline as we upgrade the service. Please see this blog post for additional details :http://blogs.adobe.com/creativecloud/update-on-creative-cloud-connecti on-and-file-sync-preview/
    All files stored in Creative Cloud can still be accessed and downloaded from the Creative Cloud web page at: https://creative.adobe.com/files
    We sincerely apologize for the inconvenience during this transition.
      by Vikrant Rai (May 17, 2013)

  • How can I  get System dates  with time scheduler using threads

    how can I get System dates with time scheduler using threads.is there any idea to update Date in my application along with system Date automatic updation...

    What the heck are you talking about and whatr has it to do with threads?
    Current time: System.currentTimeMillis. Date instances are not supposed to be updated.

  • How can I get past the error messages that keep popping up when I try to download Flash player?

    How can I get past the error messages that keep popping up every time I try to download anything?

    Hi
    Could you please let us know more about the error messages that you got?
    The following page has information on the error messages: http://helpx.adobe.com/content/help/en/flash-player/kb/installation-problems-flash-player- windows.html
    Thanks,
    Sunil

  • I downloaded 11.1 but now can't access the store, can only view my library. I've reinstalled but still get a blank, white screen when I try to go to the itunes store. How can I get to the store for purchases?

    I downloaded 11.1 but now can't access the store, can only view my library. I've reinstalled but still get a blank, white screen when I try to go to the itunes store. How can I get to the store for purchases?

    In iTunes prefs>Store - is the Store check box unchecked?
    Did you repair pemissions with Disk Utility?
    MJ

  • How can I get just the text to resize, rather than the entire web page?

    I used to be able to re-size just text on a webpage by typing Ctrl + +. Today, the entire webpage re-sizes, and when I move to another page it reverts. (I see this mostly in Facebook.). Why did this change, and can I go back to having just the text re-size?

    ''How can I get just the text to resize -- zoom text only''
    steps
    #"Alt" if no menu bar, then
    # View > Zoom > Zoom Text Only
    Zoom text of web pages - MozillaZine Knowledge Base
    :http://kb.mozillazine.org/Zoom_text_of_web_pages
    <br><small>Please mark "Solved" one answer that will best help others with a similar problem -- hope this was it.</small>

  • I have made with iweb a website on my macbook, now i want to change it, through my imac, how can I get in the program , which is on the mac book. On both computer I have Lion

    i have made with iweb a website on my macbook, now i want to change it, through my imac, how can I get in the program , which is on the mac book. On both computer I have Lion

    You need to transfer your domain.sites file from your MacBook to your iMac.  This is the file where iWeb stores all info and can be found under User/Library/Application Support/iWeb/domain.sites.
    Transfer this file from your MacBook to the same place on your iMac and double click the domain.sites file and iWeb will open it on your iMac and you can update your site from there too.

  • I downloaded pictures onto my iPhone from computer twice by mistake now when i uncheck/sync then check and sync again  i keep getting two lots of pics..how can i get just the one set again? thnx

    I downloaded pictures onto my iPhone from computer twice by mistake now when i uncheck/sync then check and sync again  i keep getting two lots of pics..how can i get just the one set again? thnx

    You're welcome.
    All photos transferred from your computer are stored in the iPhone's Photo Library regardless if you select a single album or folder of photos to be transferred or multiple albums or folders. The photos on the albums or folders of photos include a pointer to the original photos stored in the Photo Library. The photos are not duplicated taking up double the storage space. This way you can view the photos in an album or folder of photos only by selecting the album or folder, or all photos in all albums or folders by selecting Photo Library.
    Makes more sense when transferring multiple albums or folders of photos which cannot be changed when transferring only a single album or folder of photos.
    The same applies with iTunes and music playlists. A song can't be in a playlist unless it is in the main iTunes library. Placing a song in a playlist does not duplicate the song.

  • How can I get only the music I want onto my iPhone using iTunes Match

    how can I get only the music I want onto my iPhone using iTunes Match?  At present it is putting a random selection on; it has none of the same control as iTunes on my Mac.  And although I uploaded all my album artwork to iCloud, it is not transferring it back to my iPhone

    Iphone are meant to be sync to one itunes library only.
    You can copy those songs to a cd and then put a copy to your itunes media library.

  • My hard drive crashed and I have lost my Itunes library. How can I get my the music that I loaded from my own CDs back on my PC from my iPod?

    My hard drived crashed in my HP Pavilion desktop and I have installed a new one. I have Windows 2007. My Itunes library is gone. How can I get all the music that I loaded onto my iPod from my own CD's back into an Itunes library?

    The loading of audio files to iPod is designed to go one way only: computer to iPod. There are some third-party applications available which will rescue an audio library and write the files back to a PC HDD. The playlists might not copy, nor the album art work, nor videos but you might be able to recover all audio files. Some apps are open source and available for free download, for example: Senuti, Onyx. There are others which are  Windows-based; do a Google search to find out. 

Maybe you are looking for

  • Is it possible to set a default mfg_organization_id for a responsibility?

    We have a responsibility that only has access to 1 inventory organization as defined by Organization Access. Our users think it is silly that they should have to do a Change Org when there is only one responsibility to choose from. Is there any way t

  • Frequency of job BBP_GET_STATUS_2?

    CRM Gurus Can someone tell me the recommended frequency to run program BBP_GET_STATUS_2 via a background job? Does it all depend on business requirements? thanks.

  • Deactivate the automatic interpolation of data in DIAdem

    Bonjour! Nous sommes intéressés à désactiver l'interpolation que DIAdem fait automatiquement des données manquantes d'une base de données MySQL. En fait nous voudrions fixer une valeur de plage manquante à partir de laquelle l'interpolation des donné

  • How To Boot Client System on WDS for RDC

    Hi Team We are planing to install WDS on server 2008. we have 15 client system which we want to boot from server & directly give the page of RDC to client. need suggestion for bellow query. 1. do i need to create 15 image for individual client or onl

  • I cant install x-fi drivers

    Hi. I?ve downloaded the new?drivers for Vista64bit-edition. If I start it, Windows installer trys to install the Audio devices. But everytime Vista says "Creative Device Driver Installation Program has stopped working. A Problem caused the program to