-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1019 from ploxiln/uniq_rands_v2
internal/util: new UniqRands() implementation
- Loading branch information
Showing
2 changed files
with
53 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nsqio/nsq/internal/test" | ||
) | ||
|
||
func BenchmarkUniqRands5of5(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
UniqRands(5, 5) | ||
} | ||
} | ||
func BenchmarkUniqRands20of20(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
UniqRands(20, 20) | ||
} | ||
} | ||
|
||
func BenchmarkUniqRands20of50(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
UniqRands(20, 50) | ||
} | ||
} | ||
|
||
func TestUniqRands(t *testing.T) { | ||
var x []int | ||
x = UniqRands(3, 10) | ||
test.Equal(t, 3, len(x)) | ||
|
||
x = UniqRands(10, 5) | ||
test.Equal(t, 5, len(x)) | ||
|
||
x = UniqRands(10, 20) | ||
test.Equal(t, 10, len(x)) | ||
} |