Skip to content
  • Avinash Kumar's avatar
    2da4c1f5
    key, test: Replace map[Key]interface{} with key.Map · 2da4c1f5
    Avinash Kumar authored
    Also modify StringifyCollection to distinguish between key.Map and
    standard map, and handle the embedded value of a key.Key (see
    stringifyCollectionHelper).
    Also allow key.Map to be stringified in generic go string output,
    as well as when Maps are used as keys in gNMI/JSON objects/path elements
    
    Benchmark output:
    relevant benchmarks are BenchmarkSetToMap*, BenchmarkGetromMap,
    BenchmarkBigMap* (ignore BenchmarkMapGrow, BenchmarkMapGet, as they
    already compare map[Key]interface{} and key.Map)
    
    benchmark                                      old ns/op     new ns/op     delta
    BenchmarkMapGrow/map[key.Key]interface{}-4     67959         69898         +2.85%
    BenchmarkMapGrow/key.Map-4                     41993         41219         -1.84%
    BenchmarkMapGet/map[key.Key]interface{}-4      45129         48143         +6.68%
    BenchmarkMapGet/key.Map-4                      44930         47378         +5.45%
    BenchmarkSetToMapWithStringKey-4               839           714           -14.90%
    BenchmarkSetToMapWithUint64Key-4               550           500           -9.09%
    BenchmarkGetFromMapWithMapKey-4                451           462           +2.44%
    BenchmarkBigMapWithCompositeKeys-4             464           468           +0.86%
    BenchmarkBuiltInType/string-4                  64.3          63.7          -0.93%
    BenchmarkBuiltInType/int8-4                    13.7          11.4          -16.79%
    BenchmarkBuiltInType/int16-4                   37.4          36.5          -2.41%
    BenchmarkBuiltInType/int32-4                   43.1          39.0          -9.51%
    BenchmarkBuiltInType/int64-4                   40.2          45.2          +12.44%
    BenchmarkBuiltInType/uint8-4                   11.8          9.88          -16.27%
    BenchmarkBuiltInType/uint16-4                  36.2          34.4          -4.97%
    BenchmarkBuiltInType/uint32-4                  32.6          33.4          +2.45%
    BenchmarkBuiltInType/uint64-4                  38.7          38.2          -1.29%
    BenchmarkBuiltInType/float32-4                 34.4          42.8          +24.42%
    BenchmarkBuiltInType/float64-4                 37.3          40.0          +7.24%
    BenchmarkBuiltInType/bool-4                    11.3          10.4          -7.96%
    BenchmarkPointer/0-4                           0.53          0.28          -47.45%
    BenchmarkPointer/1-4                           0.53          0.28          -47.25%
    BenchmarkPointer/2-4                           0.53          0.27          -48.59%
    BenchmarkPointer/3-4                           0.52          0.27          -48.85%
    BenchmarkPointer/4-4                           0.52          0.28          -46.37%
    BenchmarkPointerAsKey/0-4                      71.5          83.9          +17.34%
    BenchmarkPointerAsKey/1-4                      130           152           +16.92%
    BenchmarkPointerAsKey/2-4                      181           207           +14.36%
    BenchmarkPointerAsKey/3-4                      219           270           +23.29%
    BenchmarkPointerAsKey/4-4                      244           282           +15.57%
    BenchmarkEmbeddedPointerAsKey/0-4              82.3          97.6          +18.59%
    BenchmarkEmbeddedPointerAsKey/1-4              78.0          93.9          +20.38%
    BenchmarkEmbeddedPointerAsKey/2-4              78.3          106           +35.38%
    BenchmarkEmbeddedPointerAsKey/3-4              81.8          86.0          +5.13%
    BenchmarkEmbeddedPointerAsKey/4-4              82.5          91.2          +10.55%
    
    benchmark                                      old allocs     new allocs     delta
    BenchmarkMapGrow/map[key.Key]interface{}-4     12             13             +8.33%
    BenchmarkMapGrow/key.Map-4                     12             12             +0.00%
    BenchmarkMapGet/map[key.Key]interface{}-4      0              0              +0.00%
    BenchmarkMapGet/key.Map-4                      0              0              +0.00%
    BenchmarkSetToMapWithStringKey-4               3              3              +0.00%
    BenchmarkSetToMapWithUint64Key-4               2              2              +0.00%
    BenchmarkGetFromMapWithMapKey-4                3              3              +0.00%
    BenchmarkBuiltInType/string-4                  2              2              +0.00%
    BenchmarkBuiltInType/int8-4                    0              0              +0.00%
    BenchmarkBuiltInType/int16-4                   2              2              +0.00%
    BenchmarkBuiltInType/int32-4                   2              2              +0.00%
    BenchmarkBuiltInType/int64-4                   2              2              +0.00%
    BenchmarkBuiltInType/uint8-4                   0              0              +0.00%
    BenchmarkBuiltInType/uint16-4                  2              2              +0.00%
    BenchmarkBuiltInType/uint32-4                  2              2              +0.00%
    BenchmarkBuiltInType/uint64-4                  2              2              +0.00%
    BenchmarkBuiltInType/float32-4                 2              2              +0.00%
    BenchmarkBuiltInType/float64-4                 2              2              +0.00%
    BenchmarkBuiltInType/bool-4                    0              0              +0.00%
    
    benchmark                                      old bytes     new bytes     delta
    BenchmarkMapGrow/map[key.Key]interface{}-4     19888         20176         +1.45%
    BenchmarkMapGrow/key.Map-4                     25053         25052         -0.00%
    BenchmarkMapGet/map[key.Key]interface{}-4      0             0             +0.00%
    BenchmarkMapGet/key.Map-4                      0             0             +0.00%
    BenchmarkSetToMapWithStringKey-4               200           228           +14.00%
    BenchmarkSetToMapWithUint64Key-4               163           147           -9.82%
    BenchmarkGetFromMapWithMapKey-4                384           384           +0.00%
    BenchmarkBuiltInType/string-4                  32            32            +0.00%
    BenchmarkBuiltInType/int8-4                    0             0             +0.00%
    BenchmarkBuiltInType/int16-4                   4             4             +0.00%
    BenchmarkBuiltInType/int32-4                   8             8             +0.00%
    BenchmarkBuiltInType/int64-4                   16            16            +0.00%
    BenchmarkBuiltInType/uint8-4                   0             0             +0.00%
    BenchmarkBuiltInType/uint16-4                  4             4             +0.00%
    BenchmarkBuiltInType/uint32-4                  8             8             +0.00%
    BenchmarkBuiltInType/uint64-4                  16            16            +0.00%
    BenchmarkBuiltInType/float32-4                 8             8             +0.00%
    BenchmarkBuiltInType/float64-4                 16            16            +0.00%
    BenchmarkBuiltInType/bool-4                    0             0             +0.00%
    
    Change-Id: I3a2309aa53b58f2e2c5c79c348a0833e3521c78d
    2da4c1f5
    key, test: Replace map[Key]interface{} with key.Map
    Avinash Kumar authored
    Also modify StringifyCollection to distinguish between key.Map and
    standard map, and handle the embedded value of a key.Key (see
    stringifyCollectionHelper).
    Also allow key.Map to be stringified in generic go string output,
    as well as when Maps are used as keys in gNMI/JSON objects/path elements
    
    Benchmark output:
    relevant benchmarks are BenchmarkSetToMap*, BenchmarkGetromMap,
    BenchmarkBigMap* (ignore BenchmarkMapGrow, BenchmarkMapGet, as they
    already compare map[Key]interface{} and key.Map)
    
    benchmark                                      old ns/op     new ns/op     delta
    BenchmarkMapGrow/map[key.Key]interface{}-4     67959         69898         +2.85%
    BenchmarkMapGrow/key.Map-4                     41993         41219         -1.84%
    BenchmarkMapGet/map[key.Key]interface{}-4      45129         48143         +6.68%
    BenchmarkMapGet/key.Map-4                      44930         47378         +5.45%
    BenchmarkSetToMapWithStringKey-4               839           714           -14.90%
    BenchmarkSetToMapWithUint64Key-4               550           500           -9.09%
    BenchmarkGetFromMapWithMapKey-4                451           462           +2.44%
    BenchmarkBigMapWithCompositeKeys-4             464           468           +0.86%
    BenchmarkBuiltInType/string-4                  64.3          63.7          -0.93%
    BenchmarkBuiltInType/int8-4                    13.7          11.4          -16.79%
    BenchmarkBuiltInType/int16-4                   37.4          36.5          -2.41%
    BenchmarkBuiltInType/int32-4                   43.1          39.0          -9.51%
    BenchmarkBuiltInType/int64-4                   40.2          45.2          +12.44%
    BenchmarkBuiltInType/uint8-4                   11.8          9.88          -16.27%
    BenchmarkBuiltInType/uint16-4                  36.2          34.4          -4.97%
    BenchmarkBuiltInType/uint32-4                  32.6          33.4          +2.45%
    BenchmarkBuiltInType/uint64-4                  38.7          38.2          -1.29%
    BenchmarkBuiltInType/float32-4                 34.4          42.8          +24.42%
    BenchmarkBuiltInType/float64-4                 37.3          40.0          +7.24%
    BenchmarkBuiltInType/bool-4                    11.3          10.4          -7.96%
    BenchmarkPointer/0-4                           0.53          0.28          -47.45%
    BenchmarkPointer/1-4                           0.53          0.28          -47.25%
    BenchmarkPointer/2-4                           0.53          0.27          -48.59%
    BenchmarkPointer/3-4                           0.52          0.27          -48.85%
    BenchmarkPointer/4-4                           0.52          0.28          -46.37%
    BenchmarkPointerAsKey/0-4                      71.5          83.9          +17.34%
    BenchmarkPointerAsKey/1-4                      130           152           +16.92%
    BenchmarkPointerAsKey/2-4                      181           207           +14.36%
    BenchmarkPointerAsKey/3-4                      219           270           +23.29%
    BenchmarkPointerAsKey/4-4                      244           282           +15.57%
    BenchmarkEmbeddedPointerAsKey/0-4              82.3          97.6          +18.59%
    BenchmarkEmbeddedPointerAsKey/1-4              78.0          93.9          +20.38%
    BenchmarkEmbeddedPointerAsKey/2-4              78.3          106           +35.38%
    BenchmarkEmbeddedPointerAsKey/3-4              81.8          86.0          +5.13%
    BenchmarkEmbeddedPointerAsKey/4-4              82.5          91.2          +10.55%
    
    benchmark                                      old allocs     new allocs     delta
    BenchmarkMapGrow/map[key.Key]interface{}-4     12             13             +8.33%
    BenchmarkMapGrow/key.Map-4                     12             12             +0.00%
    BenchmarkMapGet/map[key.Key]interface{}-4      0              0              +0.00%
    BenchmarkMapGet/key.Map-4                      0              0              +0.00%
    BenchmarkSetToMapWithStringKey-4               3              3              +0.00%
    BenchmarkSetToMapWithUint64Key-4               2              2              +0.00%
    BenchmarkGetFromMapWithMapKey-4                3              3              +0.00%
    BenchmarkBuiltInType/string-4                  2              2              +0.00%
    BenchmarkBuiltInType/int8-4                    0              0              +0.00%
    BenchmarkBuiltInType/int16-4                   2              2              +0.00%
    BenchmarkBuiltInType/int32-4                   2              2              +0.00%
    BenchmarkBuiltInType/int64-4                   2              2              +0.00%
    BenchmarkBuiltInType/uint8-4                   0              0              +0.00%
    BenchmarkBuiltInType/uint16-4                  2              2              +0.00%
    BenchmarkBuiltInType/uint32-4                  2              2              +0.00%
    BenchmarkBuiltInType/uint64-4                  2              2              +0.00%
    BenchmarkBuiltInType/float32-4                 2              2              +0.00%
    BenchmarkBuiltInType/float64-4                 2              2              +0.00%
    BenchmarkBuiltInType/bool-4                    0              0              +0.00%
    
    benchmark                                      old bytes     new bytes     delta
    BenchmarkMapGrow/map[key.Key]interface{}-4     19888         20176         +1.45%
    BenchmarkMapGrow/key.Map-4                     25053         25052         -0.00%
    BenchmarkMapGet/map[key.Key]interface{}-4      0             0             +0.00%
    BenchmarkMapGet/key.Map-4                      0             0             +0.00%
    BenchmarkSetToMapWithStringKey-4               200           228           +14.00%
    BenchmarkSetToMapWithUint64Key-4               163           147           -9.82%
    BenchmarkGetFromMapWithMapKey-4                384           384           +0.00%
    BenchmarkBuiltInType/string-4                  32            32            +0.00%
    BenchmarkBuiltInType/int8-4                    0             0             +0.00%
    BenchmarkBuiltInType/int16-4                   4             4             +0.00%
    BenchmarkBuiltInType/int32-4                   8             8             +0.00%
    BenchmarkBuiltInType/int64-4                   16            16            +0.00%
    BenchmarkBuiltInType/uint8-4                   0             0             +0.00%
    BenchmarkBuiltInType/uint16-4                  4             4             +0.00%
    BenchmarkBuiltInType/uint32-4                  8             8             +0.00%
    BenchmarkBuiltInType/uint64-4                  16            16            +0.00%
    BenchmarkBuiltInType/float32-4                 8             8             +0.00%
    BenchmarkBuiltInType/float64-4                 16            16            +0.00%
    BenchmarkBuiltInType/bool-4                    0             0             +0.00%
    
    Change-Id: I3a2309aa53b58f2e2c5c79c348a0833e3521c78d
Loading