github.com/zhongdalu/gf@v1.0.0/g/container/gtype/gtype_test.go (about)

     1  // Copyright 2018 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 this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  // go test *.go -bench=".*" -benchmem
     8  
     9  package gtype
    10  
    11  import (
    12  	"github.com/zhongdalu/gf/g/encoding/gbinary"
    13  	"strconv"
    14  	"sync/atomic"
    15  	"testing"
    16  )
    17  
    18  var it = NewInt()
    19  var it32 = NewInt32()
    20  var it64 = NewInt64()
    21  var uit = NewUint()
    22  var uit32 = NewUint32()
    23  var uit64 = NewUint64()
    24  var bl = NewBool()
    25  var bytes = NewBytes()
    26  var str = NewString()
    27  var inf = NewInterface()
    28  
    29  var at = atomic.Value{}
    30  
    31  func BenchmarkInt_Set(b *testing.B) {
    32  	for i := 0; i < b.N; i++ {
    33  		it.Set(i)
    34  	}
    35  }
    36  
    37  func BenchmarkInt_Val(b *testing.B) {
    38  	for i := 0; i < b.N; i++ {
    39  		it.Val()
    40  	}
    41  }
    42  
    43  func BenchmarkInt_Add(b *testing.B) {
    44  	for i := 0; i < b.N; i++ {
    45  		it.Add(i)
    46  	}
    47  }
    48  
    49  func BenchmarkInt32_Set(b *testing.B) {
    50  	for i := int32(0); i < int32(b.N); i++ {
    51  		it32.Set(i)
    52  	}
    53  }
    54  
    55  func BenchmarkInt32_Val(b *testing.B) {
    56  	for i := int32(0); i < int32(b.N); i++ {
    57  		it32.Val()
    58  	}
    59  }
    60  
    61  func BenchmarkInt32_Add(b *testing.B) {
    62  	for i := int32(0); i < int32(b.N); i++ {
    63  		it32.Add(i)
    64  	}
    65  }
    66  
    67  func BenchmarkInt64_Set(b *testing.B) {
    68  	for i := int64(0); i < int64(b.N); i++ {
    69  		it64.Set(i)
    70  	}
    71  }
    72  
    73  func BenchmarkInt64_Val(b *testing.B) {
    74  	for i := int64(0); i < int64(b.N); i++ {
    75  		it64.Val()
    76  	}
    77  }
    78  
    79  func BenchmarkInt64_Add(b *testing.B) {
    80  	for i := int64(0); i < int64(b.N); i++ {
    81  		it64.Add(i)
    82  	}
    83  }
    84  
    85  func BenchmarkUint_Set(b *testing.B) {
    86  	for i := uint(0); i < uint(b.N); i++ {
    87  		uit.Set(i)
    88  	}
    89  }
    90  
    91  func BenchmarkUint_Val(b *testing.B) {
    92  	for i := uint(0); i < uint(b.N); i++ {
    93  		uit.Val()
    94  	}
    95  }
    96  
    97  func BenchmarkUint_Add(b *testing.B) {
    98  	for i := uint(0); i < uint(b.N); i++ {
    99  		uit.Add(i)
   100  	}
   101  }
   102  
   103  func BenchmarkUint32_Set(b *testing.B) {
   104  	for i := uint32(0); i < uint32(b.N); i++ {
   105  		uit32.Set(i)
   106  	}
   107  }
   108  
   109  func BenchmarkUint32_Val(b *testing.B) {
   110  	for i := uint32(0); i < uint32(b.N); i++ {
   111  		uit32.Val()
   112  	}
   113  }
   114  
   115  func BenchmarkUint32_Add(b *testing.B) {
   116  	for i := uint32(0); i < uint32(b.N); i++ {
   117  		uit32.Add(i)
   118  	}
   119  }
   120  
   121  func BenchmarkUint64_Set(b *testing.B) {
   122  	for i := uint64(0); i < uint64(b.N); i++ {
   123  		uit64.Set(i)
   124  	}
   125  }
   126  
   127  func BenchmarkUint64_Val(b *testing.B) {
   128  	for i := uint64(0); i < uint64(b.N); i++ {
   129  		uit64.Val()
   130  	}
   131  }
   132  
   133  func BenchmarkUint64_Add(b *testing.B) {
   134  	for i := uint64(0); i < uint64(b.N); i++ {
   135  		uit64.Add(i)
   136  	}
   137  }
   138  
   139  func BenchmarkBool_Set(b *testing.B) {
   140  	for i := 0; i < b.N; i++ {
   141  		bl.Set(true)
   142  	}
   143  }
   144  
   145  func BenchmarkBool_Val(b *testing.B) {
   146  	for i := 0; i < b.N; i++ {
   147  		bl.Val()
   148  	}
   149  }
   150  
   151  func BenchmarkString_Set(b *testing.B) {
   152  	for i := 0; i < b.N; i++ {
   153  		str.Set(strconv.Itoa(i))
   154  	}
   155  }
   156  
   157  func BenchmarkString_Val(b *testing.B) {
   158  	for i := 0; i < b.N; i++ {
   159  		str.Val()
   160  	}
   161  }
   162  
   163  func BenchmarkBytes_Set(b *testing.B) {
   164  	for i := 0; i < b.N; i++ {
   165  		bytes.Set(gbinary.EncodeInt(i))
   166  	}
   167  }
   168  
   169  func BenchmarkBytes_Val(b *testing.B) {
   170  	for i := 0; i < b.N; i++ {
   171  		bytes.Val()
   172  	}
   173  }
   174  
   175  func BenchmarkInterface_Set(b *testing.B) {
   176  	for i := 0; i < b.N; i++ {
   177  		inf.Set(i)
   178  	}
   179  }
   180  
   181  func BenchmarkInterface_Val(b *testing.B) {
   182  	for i := 0; i < b.N; i++ {
   183  		inf.Val()
   184  	}
   185  }
   186  
   187  func BenchmarkAtomicValue_Store(b *testing.B) {
   188  	for i := 0; i < b.N; i++ {
   189  		at.Store(i)
   190  	}
   191  }
   192  
   193  func BenchmarkAtomicValue_Load(b *testing.B) {
   194  	for i := 0; i < b.N; i++ {
   195  		at.Load()
   196  	}
   197  }