Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java measuring time

  Asked By: Jasmine    Date: Nov 27    Category: Java    Views: 690
  

Does anyone how to measure time in microseconds?? I have a program
that works in milliseconds, but really really need something that
calulates in microseconds:


import java.util.*;

public class Mil {
public static void main(String[] args)
{
long x;
Date now = new Date();
long nowLong = now.getTime();
System.out.println("Value is " + nowLong);


try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
// ignore
}


Date now2 = new Date();
long nowLong2 = now2.getTime();
System.out.println("Value is " + nowLong2);
}
}

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Holly Brown     Answered On: Nov 27

Try this,

..
long etime=System.currentTimeMillis();
boolean success=processYourAction();
etime= System.currentTimeMillis()-etime;
System.out.println("elapsed time  for my aciton:"+ etime);
..
..

 
Answer #2    Answered By: Maliha Malik     Answered On: Nov 27

.. but they still all return in milliseconds.

 
Answer #3    Answered By: Edward Jones     Answered On: Nov 27

> Thanks guys... but they still all return in milliseconds.

java.sun.com/.../TimeUnit.html

Does that link help?

 
Answer #4    Answered By: Lewis Welch     Answered On: Nov 27

thats what i need... but i don't really understand how it all
works :( PLEASE PLEASE let me know if you understand all that,
please!!!

 
Answer #5    Answered By: Mike Stephens     Answered On: Nov 27

That's not really what you want, as there's no way to get the current
time in microseconds.

I shall point you to
www.seis.sc.edu/.../maven-reports.html

They have an extended Date class  that can handle microseconds. Check
out the Javadocs for MicroSecondDate.

 
Answer #6    Answered By: Adalric Fischer     Answered On: Nov 27

I honestly don't mean to be a pain, but could you please help me to
understand how i would go about using this in a java  program... i.e,
taking the time, waiting a few seconds and retaking the time
(something simply to find the difference between two times)... I
tried to make a simple program, but i'm having no luck :(

 
Answer #7    Answered By: Julia Flores     Answered On: Nov 27

> That's not really what you want, as there's no way to get the current
time  in microseconds.

I didn't look at it hard :), I just saw stuff about MircoSecond time and
offered it as a place to start :)

>
> I shall point you to
> www.seis.sc.edu/.../maven-reports.html
>
> They have an extended Date class  that can handle microseconds. Check
> out the Javadocs for MicroSecondDate.

That is totaly awesome though ... nice find.

 
Didn't find what you were looking for? Find more on Java measuring time Or get search suggestion and latest updates.




Tagged: