-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[close #404] use System.nanoTime() to calculate duration, cause System.currentTimeMillis() is not monotonic #402
[close #404] use System.nanoTime() to calculate duration, cause System.currentTimeMillis() is not monotonic #402
Conversation
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use JMH to add a micro benchmark and show the result to tell the performance difference?
this.endMS = 0; | ||
this.endNano = 0; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
this.startMS = System.currentTimeMillis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the previous startMS and switch to nanoTime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will lose the time point information if removed.
System.nanoTime()
can be only used to measure the difference of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about we use a specialized clock to calculate the difference of time more accurately without checking currentMillis() every time? I can optimize it after your PR is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
…Millis() is not monotonic Signed-off-by: marsishandsome <[email protected]>
9d8a01c
to
4136353
Compare
Signed-off-by: marsishandsome <[email protected]>
4136353
to
d784297
Compare
Signed-off-by: marsishandsome <[email protected]>
Signed-off-by: marsishandsome <[email protected]>
9121280
to
d04f417
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: marsishandsome <[email protected]>
Signed-off-by: marsishandsome <[email protected]>
a7c5c90
to
1edf58b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
/run-all-tests |
@marsishandsome merge failed. |
@marsishandsome UT failed, PTAL:
|
/run-all-tests |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-3.1 in PR #417 |
Signed-off-by: ti-srebot <[email protected]> Co-authored-by: Liangliang Gu <[email protected]>
Signed-off-by: marsishandsome [email protected]
close #404
use System.nanoTime() to calculate duration, cause System.currentTimeMillis() is not monotonic
The performance between
System.nanoTime()
andSystem.currentTimeMillis()
is almost the same.see https://www.javaadvent.com/2019/12/measuring-time-from-java-to-kernel-and-back.html