You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@YetAnotherMinion I don't think this is the case.
I've checked generated assembler code in both cases (lines 184 and 245). There are no compares and jumps, so functions will execute in constant time.
To prove that I made some simple benchmark,
#[bench]
fn bench_rotate_standard_9(b: &mut Bencher) {
b.iter(|| {
(0..1000).fold(0, |old, new| rotl64_2(old ^ new, 9))
});
}
// And 4 similar benchmarks for another rotation number
and here are the results:
test bench_rotate_custom_20 ... bench: 763 ns/iter (+/- 46)
test bench_rotate_custom_45 ... bench: 757 ns/iter (+/- 33)
test bench_rotate_custom_9 ... bench: 765 ns/iter (+/- 44)
test bench_rotate_standard_20 ... bench: 763 ns/iter (+/- 28)
test bench_rotate_standard_45 ... bench: 764 ns/iter (+/- 28)
test bench_rotate_standard_9 ... bench: 768 ns/iter (+/- 37)
Both functions has almost equal computation time for arbitrary n (on my Core i7-2630QM CPU @ 2.00GHz).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.