| nanoTime |
() |
yoix.system |
| |
Returns a
double
that represents the number of nanoseconds that have elapsed since
an arbitrary epoch that is established the first time
nanoTime
is called.
Trying to measure nanosecond time intervals greater than about 50 days
will not yield accurate results.
| |
| Example: |
The program,
import yoix.*.*;
Timer(double interval) {
double start = nanoTime();
sleep(interval);
printf("elapsed nanoseconds %d\n", nanoTime() - start);
}
Timer(.5);
Timer(.5);
Timer(.5);
Timer(.5);
Timer(.5);
should print something like
elapsed nanoseconds 692033000
elapsed nanoseconds 502105000
elapsed nanoseconds 502194000
elapsed nanoseconds 502682000
elapsed nanoseconds 502301000
on standard output.
The first time is longer than the others because the Yoix interpreter
has to the load modules that contain
sleep
and
printf
the first time they are called.
Change the program to
import yoix.stdio.printf;
import yoix.system.nanoTime;
import yoix.thread.sleep;
Timer(double interval) {
double start = nanoTime();
sleep(interval);
printf("elapsed nanoseconds %d\n", nanoTime() - start);
}
Timer(.5);
Timer(.5);
Timer(.5);
Timer(.5);
Timer(.5);
and the difference between the first time and the others
should disappear.
| | |
| Return: |
double
| | |
| See Also: |
currentTimeMillis,
date,
parseDate,
parseTimer,
sleep,
time,
timerFormat
|
|
Yoix is a registered trademark of AT&T Inc.
|