Skip to content

Commit 4cbfa90

Browse files
committed
docs: update benchmarks in README
1 parent 5a81164 commit 4cbfa90

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

Diff for: README.md

+24-19
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func main() {
3838
}
3939
```
4040

41-
## Benchmarks
41+
## Performance
4242

4343
The existing Go library that has a comparable implementation of this is
4444
[`github.com/jmcvetta/randutil`][1], which optimizes for the single operation
@@ -48,31 +48,36 @@ faster, especially for large data sets.
4848

4949
[1]: https://github.com/jmcvetta/randutil
5050

51-
Comparison of this library versus `randutil.ChooseWeighted`. For repeated
52-
samplings from large collections, `weightedrand` will be much quicker.
53-
54-
| Num choices | `randutil` | `weightedrand` |
55-
| ----------: | ------------: | -------------: |
56-
| 10 | 435 ns/op | 58 ns/op |
57-
| 100 | 511 ns/op | 84 ns/op |
58-
| 1,000 | 1297 ns/op | 112 ns/op |
59-
| 10,000 | 7952 ns/op | 137 ns/op |
60-
| 100,000 | 85142 ns/op | 173 ns/op |
61-
| 1,000,000 | 2082248 ns/op | 312 ns/op |
51+
Comparison of this library versus `randutil.ChooseWeighted` on my workstation.
52+
For repeated samplings from large collections, `weightedrand` will be much
53+
quicker:
54+
55+
| Num choices | `randutil` | `weightedrand` | `weightedrand -cpu=8`* |
56+
| ----------: | -------------: | -------------: | ---------------------: |
57+
| 10 | 201 ns/op | 38 ns/op | 2.9 ns/op |
58+
| 100 | 267 ns/op | 51 ns/op | 4.1 ns/op |
59+
| 1,000 | 1012 ns/op | 67 ns/op | 5.4 ns/op |
60+
| 10,000 | 8683 ns/op | 83 ns/op | 6.9 ns/op |
61+
| 100,000 | 123500 ns/op | 105 ns/op | 12.0 ns/op |
62+
| 1,000,000 | 2399614 ns/op | 218 ns/op | 17.2 ns/op |
63+
| 10,000,000 | 26804440 ns/op | 432 ns/op | 35.1 ns/op |
64+
65+
**: Since `v0.3.0` weightedrand can efficiently utilize a single Chooser across
66+
multiple CPU cores in parallel, making it even faster in overall throughput. See
67+
[PR#2](https://github.com/mroth/weightedrand/pull/2) for details. Informal
68+
benchmarks conducted on an Intel Xeon W-2140B CPU (8 core @ 3.2GHz,
69+
hyperthreading enabled).*
6270

6371
Don't be mislead by these numbers into thinking `weightedrand` is always the
6472
right choice! If you are only picking from the same distribution once,
6573
`randutil` will be faster. `weightedrand` optimizes for repeated calls at the
66-
expense of some setup time and memory storage.
67-
68-
*Update: Starting in `v0.3.0` weightedrand can now scale linearly to take
69-
advantage of multiple CPU cores in parallel, making it even faster. See
70-
[PR#2](https://github.com/mroth/weightedrand/pull/2) for details.*
74+
expense of some initialization time and memory storage.
7175

7276
## Caveats
7377

74-
Note this uses `math/rand` instead of `crypto/rand`, as it is optimized for
75-
performance, not a cryptographically secure implementation.
78+
Note this library utilizes `math/rand` instead of `crypto/rand`, as it is
79+
optimized for performance, and is not intended to be used for cryptographically
80+
secure requirements.
7681

7782
## Credits
7883

0 commit comments

Comments
 (0)