Skip to content

Commit

Permalink
Improving performance of generic map clone (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Macias committed Oct 14, 2022
1 parent a1e9a20 commit 4e957ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/config/generic_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type GenericMap map[string]interface{}

// Copy will create a flat copy of GenericMap
func (m GenericMap) Copy() GenericMap {
result := GenericMap{}
result := make(GenericMap, len(m))

for k, v := range m {
result[k] = v
Expand Down
17 changes: 17 additions & 0 deletions pkg/config/generic_map_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package config

import (
"fmt"
"testing"
)

func BenchmarkGenericMap_Copy(b *testing.B) {
m := GenericMap{}
for i := 0; i < 20; i++ {
m[fmt.Sprintf("key-%d", i)] = fmt.Sprintf("value-%d", i)
}

for i := 0; i < b.N; i++ {
_ = m.Copy()
}
}

0 comments on commit 4e957ce

Please sign in to comment.