-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
bench: add the zoned benchmark for Asia/Shanghai #103
Conversation
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.
Thanks!
For the future, a good commit hygiene in changes like this would be to have one commit that only does the refactor and then a second commit that introduces the new benchmark. It makes review easier. No need to do that now for this PR though.
The benchmark results show that the Asia/Shanghai
case is slower than the America/New_York
case for Jiff. Do you know why?
bench/src/bench.rs
Outdated
use chrono_tz::America::New_York; | ||
use chrono_tz::America::New_York; | ||
use chrono_tz::Asia::Shanghai; | ||
use chrono_tz::Tz; |
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.
Please follow the style of the surrounding code. Move the use
statements to the top of the function and combine them into one.
bench/src/bench.rs
Outdated
TZ_NEW_YORK => Some(New_York), | ||
TZ_SHANGHAI => Some(Shanghai), | ||
_ => None, | ||
}; |
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.
Can you use Tz::from_str_insensitive
instead?
bench/src/bench.rs
Outdated
@@ -2,6 +2,10 @@ use std::hint::black_box as bb; | |||
|
|||
use criterion::Criterion; | |||
|
|||
const TZ_NEW_YORK: &str = "America/New_York"; | |||
|
|||
const TZ_SHANGHAI: &str = "Asia/Shanghai"; |
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.
Assuming you use Tz::from_str_insensitive
, I don't think you'll need named constants any more.
bench/src/bench.rs
Outdated
); | ||
} | ||
|
||
fn instant_to_civil_datetime_static_with_specific_tz( |
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.
This function should probably be defined within instant_to_civil_datetime_static
. And since the scope is narrower there, you can just call it define
.
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.
you can just call it define.
Sorry, I don't understand it. Do you mean rename the funcation name to instant_to_civil_datetime_static_define
?
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.
No. define
. But you need to make it an inner function first:
fn instant_to_civil_datetime_static(...) {
fn define(...) {
...
}
define("America/New_York", ...);
define("Asia/Shanghai", ...);
}
Thank you for the quick review!
Got it. I'm curious, does jiff use squash merge(one commit) or rebase merge(keep multiple commits) after PR is reviewed? If rebase merge(keep multiple commits), I could re-orginaze commits during I address your comment.
#104 is one reason, and I found another reason as well, I will prepare the PR later. |
I use both strategies. It's difficult to articulate succinctly when I use them. For my own PRs, I almost always use rebase & merge because I craft the commits to be suitable for that purpose. For contributor PRs, commit hygiene usually isn't a focus and the changes tend to be small, so I squash & merge them. In rare cases of good commits from contributors, then I'll rebase and merge (usually after improving the commit messages locally). In other rare cases, I'll sometimes rewrite PRs to use multiple commits if I think the history would meaningfully benefit from it. For this change, which is pretty small, I'll very likely use squash and merge regardless of what you do. Please do not spend time reorganizing this PR into commits. I mentioned it for future PRs. Separating changes like "refactor but don't change behavior" from "change behavior" makes review easier, even if I ultimately still squash & merge. |
874b45d
to
2cebc8e
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.
Hey @BurntSushi , I have addressed all your comments, please help take a look in your free time, thanks a lot~
Thanks @BurntSushi for the review and merge! |
Some timezones have DST(daylight saving time) and others do not. For example:
When I look into Zoned::new, I found the code path with DST is very different from the code path without DST. And their performance is totally different.
So I propose to improve the instant_to_civil_datetime_static to bench DST and Non-DST separately.
Here is the benchmark result on my Mac:
Note: I will submit some PR to optimize their performance later. (Merging this PR first is useful to observe the performance change.)