Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   currentTimeMillis (http://www.velocityreviews.com/forums/t133890-currenttimemillis.html)

Aaron Fude 05-28-2004 05:00 AM

currentTimeMillis
 
Hi,

Time to satisfy my curiosity. The output of the following program
public static void main(String[] inArgv) {
int N = 1000000;
long[] times = new long[N];

for (int i = 0; i < N; i++)
times[i] = System.currentTimeMillis();

for (int i = 0; i < 10; i++)
System.out.println(times[i*(N/10)]);
}

....is

1085719861549
1085719861559
1085719861569
1085719861580
1085719861590
1085719861600
1085719861610
1085719861620
1085719861620
1085719861630

It seems that the java clock ticks in 10's of milliseconds. Is there
anything interesting anyone can say about this?

Aaron Fude




Elie De Brauwer 05-28-2004 05:10 AM

Re: currentTimeMillis
 
On Fri, 28 May 2004 01:00:04 -0400, Aaron Fude wrote:

> Hi,
>
> Time to satisfy my curiosity. The output of the following program
> public static void main(String[] inArgv) {
> int N = 1000000;
> long[] times = new long[N];
>
> for (int i = 0; i < N; i++)
> times[i] = System.currentTimeMillis();
>
> for (int i = 0; i < 10; i++)
> System.out.println(times[i*(N/10)]);
> }
>
> ...is
>
> 1085719861549
> 1085719861559
> 1085719861569
> 1085719861580
> 1085719861590
> 1085719861600
> 1085719861610
> 1085719861620
> 1085719861620
> 1085719861630
>
> It seems that the java clock ticks in 10's of milliseconds. Is there
> anything interesting anyone can say about this?
>
> Aaron Fude


Well, I can't but the api can ;-), see
http://java.sun.com/j2se/1.5.0/docs/...entTimeMillis()

Where there is stated:
"Returns the current time in milliseconds. Note that while the unit of
time of the return value is a millisecond, the granularity of the value
depends on the underlying operating system and may be larger. For example,
many operating systems measure time in units of tens of milliseconds."

On my GNU/Linux box I get the following output:
1085720831892
1085720831968
1085720832038
1085720832108
1085720832177
1085720832247
1085720832317
1085720832387
1085720832457
1085720832527

And if I alter the for loop I can output any individual tick.

hth

--
Elie De Brauwer
http://www.de-brauwer.be

No animals were hurt and no microsoft products were used during the
creation of this e-mail


Frank 05-28-2004 05:10 AM

Re: currentTimeMillis
 
This is an OS issue... AFAIKT, most OSs will cache the currentTimeMillis()
so that repeated calls won't slow down while the system checks with the
RTC. On windows, the timing resolution is around 10ms... I think I've
heard Linux folks claim they can adjust the default to be as sensative as
1 ms.

Hope this helps!

Frank

On Fri, 28 May 2004 01:00:04 -0400, Aaron Fude <aaronfude@yahoo.com> wrote:

> Hi,
>
> Time to satisfy my curiosity. The output of the following program
> public static void main(String[] inArgv) {
> int N = 1000000;
> long[] times = new long[N];
>
> for (int i = 0; i < N; i++)
> times[i] = System.currentTimeMillis();
>
> for (int i = 0; i < 10; i++)
> System.out.println(times[i*(N/10)]);
> }
>
> ...is
>
> 1085719861549
> 1085719861559
> 1085719861569
> 1085719861580
> 1085719861590
> 1085719861600
> 1085719861610
> 1085719861620
> 1085719861620
> 1085719861630
>
> It seems that the java clock ticks in 10's of milliseconds. Is there
> anything interesting anyone can say about this?
>
> Aaron Fude
>
>
>



Roedy Green 05-28-2004 05:20 AM

Re: currentTimeMillis
 
On Fri, 28 May 2004 01:00:04 -0400, "Aaron Fude" <aaronfude@yahoo.com>
wrote or quoted :

>
>It seems that the java clock ticks in 10's of milliseconds. Is there
>anything interesting anyone can say about this?



Java can't do anything about the granularity of the underlying system
clock.

The original PC's used a very crude tick timer where a tick is
65536/1193180 sec : 18.2065 per second.

I don't know if newer models are now using a more accurate clock.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Chris Uppal 05-28-2004 08:00 AM

Re: currentTimeMillis
 
Aaron Fude wrote:

> 1085719861549
> 1085719861559
> 1085719861569
> 1085719861580
> 1085719861590
> 1085719861600
> 1085719861610
> 1085719861620
> 1085719861620
> 1085719861630
>
> It seems that the java clock ticks in 10's of milliseconds. Is there
> anything interesting anyone can say about this?


You must have a very slow machine for it to take 10 milliseconds for each
iteration of such a simple loop.

;-)

-- chris



Lee Fesperman 05-28-2004 08:16 AM

Re: currentTimeMillis
 
Roedy Green wrote:
>
> On Fri, 28 May 2004 01:00:04 -0400, "Aaron Fude" <aaronfude@yahoo.com>
> wrote or quoted :
>
> >
> >It seems that the java clock ticks in 10's of milliseconds. Is there
> >anything interesting anyone can say about this?

>
> Java can't do anything about the granularity of the underlying system
> clock.
>
> The original PC's used a very crude tick timer where a tick is
> 65536/1193180 sec : 18.2065 per second.
>
> I don't know if newer models are now using a more accurate clock.


Actually, it's the way Microsoft programs the clock. The clocks on PC's provide sub-ms
granularity. I know, I wrote a real-time operating system that ran with DOS and
reprogrammed the clock to under a ms. It then interrupted DOS at the interval it
expected.

--
Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)

Aaron Fude 05-28-2004 07:03 PM

Re: currentTimeMillis
 

"Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> wrote in message
news:FISdnfy21vMqZSvdRVn-gw@nildram.net...
> Aaron Fude wrote:
>
> > 1085719861549
> > 1085719861559
> > 1085719861569
> > 1085719861580
> > 1085719861590
> > 1085719861600
> > 1085719861610
> > 1085719861620
> > 1085719861620
> > 1085719861630
> >
> > It seems that the java clock ticks in 10's of milliseconds. Is there
> > anything interesting anyone can say about this?

>
> You must have a very slow machine for it to take 10 milliseconds for each
> iteration of such a simple loop.
>
> ;-)


Oh yeah? Aren't I printing out every 100000th iteration? :)

>
> -- chris
>
>




Tony Morris 05-29-2004 03:36 AM

Re: currentTimeMillis
 
> It seems that the java clock ticks in 10's of milliseconds. Is there
> anything interesting anyone can say about this?


Hint: Microsoft Windows
Bigger Hint: API Specification
Further Reference: http://www.google.com

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform



Roedy Green 05-29-2004 04:31 AM

Re: currentTimeMillis
 
On Sat, 29 May 2004 13:36:38 +1000, "Tony Morris"
<dibblego@optusnet.com.au> wrote or quoted :

>> It seems that the java clock ticks in 10's of milliseconds. Is there
>> anything interesting anyone can say about this?


If you want something with very fine resolution consider the RDTSC
instruction and some JNI.

Somebody surely has cooked up the trivial JNI to access it. If not,
I'll do it for $25 US.

The problem is there is high overhead to the JNI call.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Liz 05-29-2004 06:30 AM

Re: currentTimeMillis
 


"Roedy Green" <look-on@mindprod.com.invalid> wrote in message
news:uc4gb05vpb0v59n8fr5mu8rna4eg6rtq7b@4ax.com...
> On Sat, 29 May 2004 13:36:38 +1000, "Tony Morris"
> <dibblego@optusnet.com.au> wrote or quoted :
>
> >> It seems that the java clock ticks in 10's of milliseconds. Is there
> >> anything interesting anyone can say about this?


I believe the resolution of time used in NTP is
something like 128 picoseconds. Maybe we
should be using that. Actually, I don't know what
the meaning of 'java click ticks' is, normally I
think about hardware and ticks, not software and ticks.

>
> If you want something with very fine resolution consider the RDTSC
> instruction and some JNI.
>
> Somebody surely has cooked up the trivial JNI to access it. If not,
> I'll do it for $25 US.
>
> The problem is there is high overhead to the JNI call.
>
> --
> Canadian Mind Products, Roedy Green.
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.





All times are GMT. The time now is 05:58 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.