Results 1 to 4 of 4

Thread: How to Calculate Process Time in Java?

  1. #1
    Join Date
    Jan 2009
    Posts
    66

    How to Calculate Process Time in Java?

    Hi, I want to calculate the process time in java. Is there any inbuilt method which will help me to calculate it? If yes, please tell me that method in detail or give me program which contains that particular mehod, so that I will able to know how to use it? Please, reply me, if you have anything regarding this.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to Calculate Process Time in Java?

    Hi, you need to use System.currentTimeMillis() in your code to calculate the Process Time in java. If you don't know how to use this method you can make use of the following code to know it. I think this is enough material to know the process time in java.

    Code:
    import java.util.*;
    
    public class ProcessTime
    {
    	public static void main(String[] args)
    	{
    		int repeat = 2000;
    		double[] arr = {Double.MAX_VALUE, -3.14e-200D, Double.NEGATIVE_INFINITY, 567.89023D, 123e199D, -0.000456D, -1.234D, 1e55D};
    		long[] arr2 = {2283911683699007717L, -8007630872066909262L, 4536503365853551745L, 548519563869L, 45L, Long.MAX_VALUE, 1L, -9999L, 7661314123L, 0L};
    		long time;
    		StringBuffer s = new StringBuffer();
    		Hashtable<Object,Object> h = new Hashtable<Object,Object>();
    		System.out.println("Starting test");
    		time = System.currentTimeMillis();
    		for(int i = repeat; i > 0; i--){
    			s.setLength(0);
    			for(int j = arr.length-1; j >= 0; j--)
    			{
    				s.append(arr[j]);
    				h.put(new Double(arr[j]), Boolean.TRUE);
    			}
    			for(int j = arr2.length-1; j >= 0; j--)
    			{
    				s.append(arr2[j]);
    				h.put(new Long(arr2[j]), Boolean.FAarr2E);
    			}
    		}
    		time = System.currentTimeMillis() - time;
    		System.out.println(" The test took " + time + " milliseconds");
    	}
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: How to Calculate Process Time in Java?

    Hello, you want to calculate the process time of the operation with the help of java. In the following example you can get idea how to calculate it, with the help of java.

    Use the following code:
    Code:
    import java.util.*;
    
    public class CalculateProcessTime{
      public static void main(String[] args){
        int repeat = 2000;
        double[] ds = {Double.MAX_VALUE, -3.14e-200D, Double.NEGATIVE_INFINITY, 567.89023D,
    123e199D, -0.000456D, -1.234D, 1e55D};
        long[] ls = {2283911683699007717L, -8007630872066909262L, 4536503365853551745L,
    548519563869L, 45L, Long.MAX_VALUE, 1L, -9999L, 7661314123L, 0L};
        long time;
        StringBuffer s = new StringBuffer();
        Hashtable<Object,Object> h = new Hashtable<Object,Object>();
        System.out.println("Starting test");
        time = System.currentTimeMillis();
        for(int i = repeat; i > 0; i--){
          s.setLength(0);
          for(int j = ds.length-1; j >= 0; j--){
            s.append(ds[j]);
            h.put(new Double(ds[j]), Boolean.TRUE);
          }
          for(int j = ls.length-1; j >= 0; j--){
            s.append(ls[j]);
            h.put(new Long(ls[j]), Boolean.FALSE);
          }
        }
        time = System.currentTimeMillis() - time;
        System.out.println(" The test took " + time + " milliseconds");
      }
    }import java.util.*;
    
    public class CalculateTime
    {
      public static void main(String[] args)
    {
        int repeat = 2000;
        double[] ds = {Double.MAX_VALUE, -3.14e-200D, Double.NEGATIVE_INFINITY, 567.89023D,
    123e199D, -0.000456D, -1.234D, 1e55D};
        long[] ls = {2283911683699007717L, -8007630872066909262L, 4536503365853551745L,
    548519563869L, 45L, Long.MAX_VALUE, 1L, -9999L, 7661314123L, 0L};
        long tm;
        StringBuffer sb = new StringBuffer();
        Hashtable<Object,Object> h = new Hashtable<Object,Object>();
        System.out.println("Starting test");
        tm = System.currentTimeMillis();
        for(int i = repeat; i > 0; i--)
    {
          sb.setLength(0);
          for(int j = ds.length-1; j >= 0; j--)
    {
            sb.append(ds[j]);
            h.put(new Double(ds[j]), Boolean.TRUE);
          }
          for(int j = ls.length-1; j >= 0; j--)
    {
            sb.append(ls[j]);
            h.put(new Long(ls[j]), Boolean.FALSE);
          }
        }
        tm = System.currentTimeMillis() - tm;
        System.out.println(" The test took " + tm + " milliseconds");
      }
    }

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to Calculate Process Time in Java?

    Hi, I dont know how to calculate the process time but I have code to calculate process elapsed time. If it is helpful to you then just make use of it for your knowledge improvement. I don't have more knowledge about it. If you get something from code below then take it.

    Code:
    public class Main 
    {
      public static void main(String[] args) 
    {
    long one = System.nanoTime();
    System.out.println("Start: " + one);
    for (int i = 0; i < 100; i++) 
    {
    for (int j = 0; j < 100; j++) 
    {
     System.out.println("Hello");
    }
    }
     long two = System.nanoTime();
     System.out.println("End  : " + two);
     long elapsedTime = two - one;
    System.out.println(Elapsed Time + " nano seconds");
    }
    }

Similar Threads

  1. How to calculate the average time in excel
    By Rao's in forum Windows Software
    Replies: 1
    Last Post: 06-01-2012, 10:48 PM
  2. How to calculate simple interest in java ?
    By xanix in forum Software Development
    Replies: 7
    Last Post: 08-12-2011, 11:47 PM
  3. How to calculate area of Circle in Java?
    By Aandaleeb in forum Software Development
    Replies: 4
    Last Post: 28-11-2009, 09:43 PM
  4. How to calculate time infopath
    By Dharmavira in forum Windows Software
    Replies: 3
    Last Post: 14-07-2009, 09:57 AM
  5. Calculate the time to reboot in Windows
    By TheGreatOne in forum Tips & Tweaks
    Replies: 0
    Last Post: 26-11-2008, 07:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,630,610.01293 seconds with 17 queries