-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Update fannkuchredux benchmark #16999
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
From the discussion on reddit: http://www.reddit.com/r/rust/comments/2fenlg/benchmark_improvement_fannkuchredux/ This adds two variants: the primary, that uses an unsafe block, and a secondary that is completely safe. The one with the unsafe block matches clang's performance and beats gcc's.
Hm, is adjusting |
@huonw I'm testing that change to |
@huonw Optimized |
It'd be awesome if we would show off idiomatic rust code beating/matching C++ rather than straight ports of the C++ benchmarks, and I'm curious, with the |
http://www.reddit.com/r/rust/comments/2fenlg/benchmark_improvement_fannkuchredux/ck8swcx?context=1 Iirc the 'original' listed there uses @dotdash's reverse (the fast one), but I can't remember exactly which |
|
Ah, no, I think that 'original' was the truly original code (makes sense...), but just substituting in the faster |
unsafe { | ||
let pa: *mut T = self.unsafe_mut_ref(i); | ||
let pb: *mut T = self.unsafe_mut_ref(ln - i - 1); | ||
ptr::swap(pa, pb); |
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 this just be mem::swap instead? That way there's no raw ptrs.
Shouldn't we prefer the neater alternative, also by @brson Edit: I don't think we need to leave a note saying it improves a benchmark. It's a valid optimization as observed in other functions as well.
|
I'm not clear on what people are suggesting happens here. |
Updated the description of the second commit. |
This makes the completely safe implementation of fannkuchredux perform the same as C++. Yay, Rust.
I removed the comment about fankuch. mem::swap can't be used here because of borrowing conflicts. |
I would r+ but I wrote the code, basically, so that feels bad. :) |
From the discussion on reddit: http://www.reddit.com/r/rust/comments/2fenlg/benchmark_improvement_fannkuchredux/ This adds two variants: the primary, that uses an unsafe block, and a secondary that is completely safe. The one with the unsafe block matches clang's performance and beats gcc's.
From the discussion on reddit:
http://www.reddit.com/r/rust/comments/2fenlg/benchmark_improvement_fannkuchredux/
This adds two variants: the primary, that uses an unsafe block, and a secondary
that is completely safe.
The one with the unsafe block matches clang's performance and beats gcc's.