github.com/zhongdalu/gf@v1.0.0/g/container/gmap/gmap_z_bench_unsafe_test.go (about)

     1  // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with gm file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  // go test *.go -bench=".*" -benchmem
     8  
     9  package gmap_test
    10  
    11  import (
    12  	"strconv"
    13  	"testing"
    14  
    15  	"github.com/zhongdalu/gf/g/container/gmap"
    16  )
    17  
    18  var ififmUnsafe = gmap.New(true)
    19  var iimUnsafe = gmap.NewIntIntMap(true)
    20  var iifmUnsafe = gmap.NewIntAnyMap(true)
    21  var ismUnsafe = gmap.NewIntStrMap(true)
    22  var simUnsafe = gmap.NewStrIntMap(true)
    23  var sifmUnsafe = gmap.NewStrAnyMap(true)
    24  var ssmUnsafe = gmap.NewStrStrMap(true)
    25  
    26  // Writing benchmarks.
    27  
    28  func Benchmark_Unsafe_IntIntMap_Set(b *testing.B) {
    29  	for i := 0; i < b.N; i++ {
    30  		iimUnsafe.Set(i, i)
    31  	}
    32  }
    33  
    34  func Benchmark_Unsafe_IntAnyMap_Set(b *testing.B) {
    35  	for i := 0; i < b.N; i++ {
    36  		iifmUnsafe.Set(i, i)
    37  	}
    38  }
    39  
    40  func Benchmark_Unsafe_IntStrMap_Set(b *testing.B) {
    41  	for i := 0; i < b.N; i++ {
    42  		ismUnsafe.Set(i, strconv.Itoa(i))
    43  	}
    44  }
    45  
    46  func Benchmark_Unsafe_AnyAnyMap_Set(b *testing.B) {
    47  	for i := 0; i < b.N; i++ {
    48  		ififmUnsafe.Set(i, i)
    49  	}
    50  }
    51  
    52  func Benchmark_Unsafe_StrIntMap_Set(b *testing.B) {
    53  	for i := 0; i < b.N; i++ {
    54  		simUnsafe.Set(strconv.Itoa(i), i)
    55  	}
    56  }
    57  
    58  func Benchmark_Unsafe_StrAnyMap_Set(b *testing.B) {
    59  	for i := 0; i < b.N; i++ {
    60  		sifmUnsafe.Set(strconv.Itoa(i), i)
    61  	}
    62  }
    63  
    64  func Benchmark_Unsafe_StrStrMap_Set(b *testing.B) {
    65  	for i := 0; i < b.N; i++ {
    66  		ssmUnsafe.Set(strconv.Itoa(i), strconv.Itoa(i))
    67  	}
    68  }
    69  
    70  // Reading benchmarks.
    71  
    72  func Benchmark_Unsafe_IntIntMap_Get(b *testing.B) {
    73  	for i := 0; i < b.N; i++ {
    74  		iimUnsafe.Get(i)
    75  	}
    76  }
    77  
    78  func Benchmark_Unsafe_IntAnyMap_Get(b *testing.B) {
    79  	for i := 0; i < b.N; i++ {
    80  		iifmUnsafe.Get(i)
    81  	}
    82  }
    83  
    84  func Benchmark_Unsafe_IntStrMap_Get(b *testing.B) {
    85  	for i := 0; i < b.N; i++ {
    86  		ismUnsafe.Get(i)
    87  	}
    88  }
    89  
    90  func Benchmark_Unsafe_AnyAnyMap_Get(b *testing.B) {
    91  	for i := 0; i < b.N; i++ {
    92  		ififmUnsafe.Get(i)
    93  	}
    94  }
    95  
    96  func Benchmark_Unsafe_StrIntMap_Get(b *testing.B) {
    97  	for i := 0; i < b.N; i++ {
    98  		simUnsafe.Get(strconv.Itoa(i))
    99  	}
   100  }
   101  
   102  func Benchmark_Unsafe_StrAnyMap_Get(b *testing.B) {
   103  	for i := 0; i < b.N; i++ {
   104  		sifmUnsafe.Get(strconv.Itoa(i))
   105  	}
   106  }
   107  
   108  func Benchmark_Unsafe_StrStrMap_Get(b *testing.B) {
   109  	for i := 0; i < b.N; i++ {
   110  		ssmUnsafe.Get(strconv.Itoa(i))
   111  	}
   112  }