File tree Expand file tree Collapse file tree 4 files changed +37
-10
lines changed Expand file tree Collapse file tree 4 files changed +37
-10
lines changed Original file line number Diff line number Diff line change
1
+ module github.com/segmentio/go-hll
2
+
3
+ go 1.12
4
+
5
+ require (
6
+ github.com/davecgh/go-spew v1.1.0
7
+ github.com/pkg/errors v0.8.0
8
+ github.com/pmezard/go-difflib v1.0.0
9
+ github.com/stretchr/testify v1.2.2
10
+ )
Original file line number Diff line number Diff line change
1
+ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 =
2
+ github.com/davecgh/go-spew v1.1.0 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
3
+ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw =
4
+ github.com/pkg/errors v0.8.0 /go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0 =
5
+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
6
+ github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
7
+ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w =
8
+ github.com/stretchr/testify v1.2.2 /go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs =
Original file line number Diff line number Diff line change @@ -130,23 +130,21 @@ type settings struct {
130
130
// This function will also compute and populate auto-generated thresholds and
131
131
// constant values used by the Hll calculations and cache the result.
132
132
func (s Settings ) toInternal () (* settings , error ) {
133
-
134
133
if err := s .validate (); err != nil {
135
134
return nil , err
136
135
}
137
136
138
- log2m := s .Log2m
139
- regwidth := s .Regwidth
137
+ settingsCacheLock .RLock ()
138
+ cachedSettings := settingsCache [s ]
139
+ settingsCacheLock .RUnlock ()
140
140
141
- // try to get the settings
142
- if settings := func () * settings {
143
- settingsCacheLock .RLock ()
144
- defer settingsCacheLock .RUnlock ()
145
- return settingsCache [s ]
146
- }(); settings != nil {
147
- return settings , nil
141
+ if cachedSettings != nil {
142
+ return cachedSettings , nil
148
143
}
149
144
145
+ log2m := s .Log2m
146
+ regwidth := s .Regwidth
147
+
150
148
var explicitThreshold int
151
149
explicitAuto := s .ExplicitThreshold == AutoExplicitThreshold
152
150
if explicitAuto {
Original file line number Diff line number Diff line change @@ -136,3 +136,14 @@ func resetDefaults() {
136
136
defaultSettings = nil
137
137
defaultSettingsLock .Unlock ()
138
138
}
139
+
140
+ func BenchmarkSettingsToInternal (b * testing.B ) {
141
+ s := Settings {
142
+ Log2m : 11 ,
143
+ Regwidth : 5 ,
144
+ }
145
+
146
+ for i := 0 ; i < b .N ; i ++ {
147
+ s .toInternal ()
148
+ }
149
+ }
You can’t perform that action at this time.
0 commit comments