This repository was archived by the owner on Feb 1, 2023. It is now read-only.
Use bigint Binomial for Choose function#29
Open
jpgoldberg wants to merge 2 commits into
Open
Conversation
Instead of having our own N choose K function, use Binomial from math/big. Because our code seems to want everything to be float64, there is some funky conversion going on.
Owner
|
I didn't even notice that I spelled choose wrong. I have some time coming up later this week and wanted to spend some time on this library, so i will take a deeper look at this (and other PRs) then. for why floats are used. . . I can't remember. I wrote this when I was first learning Go and it has many many issues that I need to go back and fix. |
Owner
|
So other than the benchmarks it looks fine func Benchmark_NChoseK(b *testing.B) {
for n := 0; n < b.N; n++ {
NChoseK(100,2)
}
}
func Benchmark_NChoseKOld(b *testing.B) {
for n := 0; n < b.N; n++ {
NChoseKOld(100,2)
}
}To see how this would impact the who algorithm i created these benchmarks. func Benchmark_1(b *testing.B) {
for n := 0; n < b.N; n++ {
GoPasswordStrength("zxcvbn", nil)
}
}
func Benchmark_2(b *testing.B) {
for n := 0; n < b.N; n++ {
GoPasswordStrength("Tr0ub4dour&3", nil)
}
}
func Benchmark_3(b *testing.B) {
for n := 0; n < b.N; n++ {
GoPasswordStrength("neverforget13/3/1997", nil)
}
}
func Benchmark_4(b *testing.B) {
for n := 0; n < b.N; n++ {
GoPasswordStrength("briansmith4mayor", nil)
}
}
func Benchmark_5(b *testing.B) {
for n := 0; n < b.N; n++ {
GoPasswordStrength("Ba9ZyWABu99[BK#6MBgbH88Tofv)vs$", nil)
}
}
func Benchmark_6(b *testing.B) {
for n := 0; n < b.N; n++ {
GoPasswordStrength("rWibMFACxAUGZmxhVncy", nil)
}
}With Old With New NChoseK @jpgoldberg What do you think? |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
A comment in the original said,
The choose function is also known as the binomial coefficient, and this exists in math/big for Ints.
What
This PR replaces the contents of
NChoseK()with a call to math/big'sBinomial(). It does some conversions so that no changes need to be made in how NChoseK is called.Why?
Why make this change?
What this doesn't do
Possible objections
Although I do acknowledge those as legitimate objections, I wouldn't be submitting this PR if I didn't think the benefits outweigh them.