-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix the calculation in SleepForMilliseconds #153
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
Conversation
static_cast should be done after the multiplication operation.
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.
求问这句能解释下么XD
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.
milliseconds is already an integer, it doesn't need to be casted to integer again. Instead, kNumMicrosPerMilli is a long, so after multiplication, it needs to be casted into int.
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.
多谢哈 您在akuna么 我看到你的题解了XD 那里感觉如何哇
|
If we choose to perform the cast we should assert that the value is representative is the new type. We don't want to silently truncate. @dominichamon Should we change the interface of these functions to take |
|
The current code doesn't check the overflow sadly... https://github.com/google/benchmark/blob/master/src/sleep.cc#L47 |
|
We could change to size_t, or int64_t, but we'd end up truncating in some cases as I'm not sure that choosing We should check for overflow, or at least potential overflow, before the multiplications. |
|
I'm afraid you didn't do your math correctly, @dominichamon. 32 bits in nanoseconds is about 4 seconds. |
|
see, this is why i shouldn't be allowed to write anything on the internet before coffee. thanks, @pleroy. in There's a subtle bug in I think the correct approach is to take |
|
@guanqun can you make the changes from the above discussion, or would you rather abandon this PR and i'll create an issue for the above? |
|
@dominichamon give me two days and I'll try to fix this. Otherwise it's all yours. :D |
|
This patch isn't needed. You're right that the static cast is incorrect, but it's also entirely unneeded. The correct thing is to remove the cast entirely, which has already been done. |
static_cast should be done after the multiplication operation. Otherwise the milliseconds is already an int.