public
class
ChenPi
{
public
static
void
main
(
String
[
]
args
)
throws
InterruptedException
{
long
startTime
=
System
.
currentTimeMillis
(
)
;
Thread
.
sleep
(
1000
)
;
long
endTime
=
System
.
currentTimeMillis
(
)
;
System
.
out
.
println
(
"执行耗时(ms):"
+
(
endTime
-
startTime
)
)
;
执行耗时
(
ms
)
:
1011
但如果我们想对多个代码段进行计时,以及每个阶段计时的占比等信息,如果还是采用如上的方式就会充斥比较多的与业务无关的代码,不够简洁。