Testing time taken by a Java Program

Dear all,
Would the following code suffice in getting a good average running time of a Java program.
long start, end;
float seconds;
long counter = 0;
start = System.currentTimeMillis();//get starting time
while((System.currentTimeMillis() - start) < 100000){
//call your program
counter++;
end = System.currentTimeMillis();
seconds = (end - start)/1000;
System.out.println("seconds :- " + seconds +" counter:- " + counter );
System.out.println("Average time:- " + (seconds/counter));
Thanks in advance for any help

well.. what pops out immediatly is that you didnt calculate first how long the loop itself takes.
meaning.. in the time result that you get, there are also all the loop operations.
measure an empty look running the same number of times and reduce it from your result.
by the way, do you know an easy way to decide if a string can be a valid class name?

Similar Messages

  • How to check the Memory consumtions and time taken by a Java Program??

    HI all,
    I want to know how to check for the Memory Usage of an XML Parser.
    See, a product was developed completely in DOM parser and now I am replacing that thing with SAX Parser Completely, because the DOM parser was taking huge memory as u may have guessed.
    BUt the thig is that, now I want to check how much memory is being taken by the SAX parser alone and DOM parser alone so that I can compare them.
    Can anyone suggest me how to do that ???
    Thanx in Advance
    Kaushik

    Thanx boss ..thanx a lot
    I tried that, but in the API docs, it is mentioned that freeMemory()Returns the amount of free memory "in the system"
    and totalMemory() Returns the total amount of memory in the "Java Virtual Machine".
    So if I compare both the Values then would it give the Correct result to me ???? Beacuse the freeMemory() gives the data in terms of the Host System whereas totalMemory() provides the data in terms of Java Virtual Machine ..... are they Same ?????
    I think I am clear in explaining what exactly is going on my mind ...
    Please clarify
    Thanx again
    Kaushik

  • Quick time not work with java programming

    I'm student and I want to use java .
    but it don't work with quick time .
    java can't run if I have quick time in my computer .
    (It works if I uninstall quick time)
    And how can I use iTunes without quicktime Or how can I
    fix that problem .
    Some one pls. HALP ME!!!!!
    Notebook   Windows XP Pro  

    Help Apple, Please!!!!
    I have still this problem!
    If I install QuickTime (7.0.3) all Java applications will not run.
    It works if I uninstall QuickTime...!
    Please help!
    Thanks

  • Where to place    text file in  Jdeveloper9irc  to read from Java program

    For ex.
    package mypackage;
    import java.io.*;
    public class ReadData
    public ReadData()
    public static void main(String[] args)
    new ReadData();
    try{
    File fin = new File("test.txt");
    if (fin.canRead())
    System.out.println("Can read file");
    I am geting a error message of file not found. Please advise
    in which directory should I place the text file "test.txt" so that the java program can read from it.
    Thanks,
    agsp

    The test.txt file should be in the 'Run Directory" of your Project. Select Project.jpr and invoke Project settings dialog.
    Click on the Runner. You will see the "Run Directory" edit field.
    For ex.
    package mypackage;
    import java.io.*;
    public class ReadData
    public ReadData()
    public static void main(String[] args)
    new ReadData();
    try{
    File fin = new File("test.txt");
    if (fin.canRead())
    System.out.println("Can read file");
    I am geting a error message of file not found. Please advise
    in which directory should I place the text file "test.txt" so that the java program can read from it.
    Thanks,
    agsp

  • How can isend use the outlook express to send,receive in our java program

    hello guys.
    i want to use the outlook express in my java program because it is already built. so we need not write the every feature. does any body know it(how to do it). please i want source code.
    any reply will be appreciated greatly

    Hi,
    When I execute the command like "Runtime.getRuntime().exec("cmd /c start mailto:[email protected]?subject=Test&body=Hello");" in my java program,There is no boby in my outlook window .could you give me some suggestion? Thank you very much!
    source:
    import java.io.IOException;
    public class TestAutoSendEMail {
         public static void main(String[] args) {
              try {  
                   Runtime.getRuntime().exec("cmd /c start mailto:[email protected]?subject=Test&body=Hello");
         catch (IOException ex) {  
         System.out.println(ex.getMessage());
    }

  • Running a java program a set number of times

    This is a general question. Is it possible to make a java program run only 5 times for the sake of arguement.
    Basically I want to write a program that will give the user some flexibility when it will actually run another Java program, but I only want them to be able to say "not now' for a set number of times. When the last time comes the other program will launch. I was initially thinking of the Do Whilw loop, but this needs to work when the program is restarted.
    Program starts, it has 5 times it will run before it does something else(doesn't really matter now I think). User takes option "Not Now" and the program ends, but warns the user this will run 4 more times before you will need to do something.
    This process will repeat until the user takes the option "Ok install now" or the time limit expires and the install occurs anyway. Can someone point me in the right direction.

    ok I see so it's like one those programs that you download for free on the internet and they give you a set amount times to use it before you have to pay for it. but in this case when the number of times you use it equals 5 (or when the user clicks ok) a different java app will open automatically.
    My first thought would be to Write a Serialized object to disk using objectOutputStream that stores the number of times the application has been opened. and each time the program runs it checks for the serialized object and then you can do something like what I posted before. of course if were worried about security the user could always look for the object and erase it, if so then I guess we would have to come up with another plan of attack
    Hope this helps

  • Is there a method I can use to test the space cost of a Java program?

    I am trying to test the space cost of a Java program (or a few lines of executed codes), however...
    Firstly I tried to use the method freeMemory() in runtime class at start and end of a number of lines tested on, and then find the differences between them. But because I don't know when JVM releases memories, this idea seems not working.
    I also tries to use the -verbose:gc to print the GC actions, which is also hard to be automatically collected (Computing the results one by one by hand is too burdensome).
    Is there a method in some classes can be used for doing this? Could anyone help me on this, please?

    Up _+ ...                                                                                                                                                                                                                                                       

  • How can i create a test suite in oracle for a java program

    hi
    i have to create a table for test cases for a java program
    in that my main concentration is on branch statements
    i have problems to choose which fields should be there in my table
    plz let me know if you have nay ideas
    thnx
    regards
    [email protected]

    no idea based on the little or nothing you've posted.
    %

  • How to change system time through java program

    Hi
    I want to know, how to change system time through java program.
    give me a idia with example.
    Thanks

    There isn't any core Java API for this. Use JNI or call an external process with Runtime.exec().
    ~

  • A Java program that runs automatically at a given time of day

    Okay Iam at the ending stages of a Java Assignment that is a MySql database, Hibernate for Mapping with a Java Server Faces front-end. All I need to do now is send emails at set time every week. Normally I know what to search for but frankly Iam stumped. Iam really just looking for a starting point for something that can run a Java Program at a set time of the week. PS my OS is Ubuntu if that is relevant but I was hoping for something that isn't platform specific so that it is portable.
    Cheers in advance.

    You can use the possibilities of your operating system, in this case Ubuntu.
    Just drop a shell script that runs your java program in the /etc/cron.weekly directory.
    --janeiros                                                                                                                                                                                                                                                                                                                                                                   

  • Is it possible to automate the running of a java program multiple times?

    For example, i have a java program which constantly writes the word "hello world" to a text file and ends the program.
    Instead of compiling & running this multiple times is there a way to automate it and it will run it many times as you want?

    Theresonly1 wrote:
    For example, i have a java program which constantly writes the word "hello world" to a text file and ends the program.
    Instead of compiling & running this multiple times is there a way to automate it and it will run it many times as you want?What do you mean by "constantly" and "many times as you want"? Do you mean literally constantly -- as soon as it runs, it runs immediately again?
    Or do you mean something like running it once every half hour indefinitely?
    What i was looking for is something along the lines of a script file or Ant. Like an automation tool. How is this not answering your own question? You can use a script, or Ant.

  • How to find that a java program is running for the first time on daily basi

    it is like this
    1. i will ran a java program every day and i have to find that it is running for the first time(as i may stop that program and may run again the same day )
    Pls share ur ideas

    san.kumar wrote:
    it is like this
    1. i will ran a java program every day and i have to find that it is running for the first time(as i may stop that program and may run again the same day )
    Pls share ur ideasAs kajbj said - you need to store a token / file with a run date on the file system. Each time the application runs, have it compare with the date from this file with the current date. If different, it's the first run of the day. If not, it is not the first run of the day. Each time have it update the date on the file.

  • I want to test a java program[UDDI  JAVAse1.4/2004] that uses:

    I want to test a java program[UDDI  JAVAse1.4/2004] that uses:
    1.http://test.uddi.microsoft.com/inquire
    2.https://test.uddi.microsoft.com/publish
    wel las of today(now) these urls changed or remain and are functional the same? if non, tell me new ones?

    According to Wikipedia
    IBM, Microsoft, and SAP announced they were closing their public UDDI nodes in January 2006.UDDI didn't take off as much as was hoped and public UDDI nodes never were much use. These days UDDI is used very rarely and mostly in-house.

  • Execute Java Program in a specific time everyday

    Hi All,
    I need help for Execute Java Program in a specific time everyday.
    I want to do insert data into database every 3:00 AM everyday.
    I thought there is a one thread program will do. It is correct my understanding? Please let me know and guide me How can I do?
    Thanks
    Amit

    If you are using Window$ then you can create a bat file to execute the program and place the bat file in Scheduled Tasks.

  • How to deal with time in Java program?

    It is very common that when you install a program, there is a bar showing the progress of the installation. My question is how to build such a bar in my Java GUI?
    Also, I would like to insert an underlying clock, recording the time spent in running the program, and return the value to the user.
    Could anyone tell me how to achieve those? Thanks in advance!

    It is very common that when you install a program,
    there is a bar showing the progress of the
    installation. My question is how to build such a bar
    in my Java GUI? JProgressBar. There's a tutorial.
    Also, I would like to insert an underlying clock,
    recording the time spent in running the program, and
    return the value to the user. System.currentTimeMillis()

Maybe you are looking for

  • ALV report - remove of decimal values

    Hi experts, In my ALV report, output table having decimal values, ex:90000.50, i want to display only 90000, can help any one inthis. Thanks in advance. Regards Rams

  • Living In A GARDEN BUBBLE

    I feel like I've been living in a garden bubble for the last 12 months. I'm comfortable with this for the most part, but when I look through 'The Bubble' at MyFICO Approval Forums, occasionally I get sad--sad for me, but happy for the members who wer

  • How do I transfer library on i pod to laptop

    52 year old computer idiot here. My main computer crashed and I lost everything. I now have a hp laptop with windows 7. I downloaded i tunes to the laptop but when I connect my i pod it says I am already synced to another library. I have been searchi

  • Kate always open files in a new window after kde upgrade

    kate always open files in a new window, instead of the existing window as a new document after kde upgrade to 3.5. someone else have the same experience and have a solution for that ? cheers, notz

  • Problem with Oracle Adaptive Access Manager 10g

    Hello, I'm trying to install the OAAM following the Installation and Configuration Guide (http://download.oracle.com/docs/cd/E12057_01/doc.1014/e12050/toc.htm). In The Package Contents section speaks of a zip file named oaam_bin.zip but never says wh