-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
AreAllMsgDifferent: Use [32]byte instead of string for less memory allocation #15
Conversation
Thank you for the useful patch.
What does this mean? set is not array.
And I reduced the copy. Is it okay? |
You can make a map of a given size. Without make this method is almost as slow as it was before with more allocation.
I have tested benchmarked these implementations below. My changes:
Your changes:
Your changes with
Performance is pretty close, but the number of allocations is different. Given these results, I would recommend not using Some additional reading on golang maps can be found here, if it's helpful. https://blog.golang.org/maps |
I see, then It seems to be better to set not
The two results shows w/ and wo/ |
Oops! Yes, I meant to make it size n. I’ll follow up tomorrow morning, thanks! |
func AreAllMsgDifferent(msgVec []byte) bool { | ||
const MSG_SIZE = 32 | ||
n := len(msgVec) / MSG_SIZE | ||
set := make(map[[MSG_SIZE]byte]struct{}, MSG_SIZE) |
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.
Sorry, I forgot to fix this
I've already fixed it at master branch. |
Key changes:
I wrote a quick benchmark to test this
https://gist.github.com/prestonvanloon/0e4645135a43c155b908939ec1428536