@@ -38,7 +38,7 @@ func main() {
38
38
}
39
39
```
40
40
41
- ## Benchmarks
41
+ ## Performance
42
42
43
43
The existing Go library that has a comparable implementation of this is
44
44
[ ` github.com/jmcvetta/randutil ` ] [ 1 ] , which optimizes for the single operation
@@ -48,31 +48,36 @@ faster, especially for large data sets.
48
48
49
49
[ 1 ] : https://github.com/jmcvetta/randutil
50
50
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).*
62
70
63
71
Don't be mislead by these numbers into thinking ` weightedrand ` is always the
64
72
right choice! If you are only picking from the same distribution once,
65
73
` 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.
71
75
72
76
## Caveats
73
77
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.
76
81
77
82
## Credits
78
83
0 commit comments