|
| |||||||||
| Tags: calculate, java, process, program, time |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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
| ||||
| ||||
| 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");
}
}
__________________ Grand Theft Auto 4 PC Video Game |
|
#3
| ||||
| ||||
| 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 |
|
#4
| ||||
| ||||
| 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");
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |