Java Reference
In-Depth Information
main
.
invoke
(
null
null
,
nargs
);
// Get ending time, and compute usage
long
long
t1
=
System
.
currentTimeMillis
();
long
long
runTime
=
t1
-
t0
;
System
.
err
.
println
(
"runTime="
+
Double
.
toString
(
runTime
/
1000
D
));
}
}
Of course, you can't directly compare the results from the operating system
time
command
with results from running this program. There is a rather large, but fairly constant, initializa-
tion overhead—the JVM startup and the initialization of
Object
and
System.out
, for ex-
ample—that is included in the former and excluded from the latter. One could even argue
that my
Time
program is more accurate because it excludes this constant overhead. But, as
noted, it must be run on a single-user machine to yield repeatable results. And no fair run-
ning an editor in another window while waiting for your timed program to complete!
See Also
Java Performance: The Definitive Guide
by Scott Oaks (O'Reilly) provides information on
tuning Java performance.
Printing Class Information
Problem
You want to print all the information about a class, similar to the way
javap
does.
Solution
Get a
Class
object, call its
getFields()
and
getMethods()
, and print the results.