Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



How to Calculate Process Time in Java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 08-12-2009
Member
 
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.
Reply With Quote
  #2  
Old 08-12-2009
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
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");
	}
}
Reply With Quote
  #3  
Old 08-12-2009
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
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");
  }
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 08-12-2009
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,832
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");
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 07:47 AM.