mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
vendor files
This commit is contained in:
135
vendor/google.golang.org/grpc/benchmark/primitives/code_string_test.go
generated
vendored
Normal file
135
vendor/google.golang.org/grpc/benchmark/primitives/code_string_test.go
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package primitives_test
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
type codeBench uint32
|
||||
|
||||
const (
|
||||
OK codeBench = iota
|
||||
Canceled
|
||||
Unknown
|
||||
InvalidArgument
|
||||
DeadlineExceeded
|
||||
NotFound
|
||||
AlreadyExists
|
||||
PermissionDenied
|
||||
ResourceExhausted
|
||||
FailedPrecondition
|
||||
Aborted
|
||||
OutOfRange
|
||||
Unimplemented
|
||||
Internal
|
||||
Unavailable
|
||||
DataLoss
|
||||
Unauthenticated
|
||||
)
|
||||
|
||||
// The following String() function was generated by stringer.
|
||||
const _Code_name = "OKCanceledUnknownInvalidArgumentDeadlineExceededNotFoundAlreadyExistsPermissionDeniedResourceExhaustedFailedPreconditionAbortedOutOfRangeUnimplementedInternalUnavailableDataLossUnauthenticated"
|
||||
|
||||
var _Code_index = [...]uint8{0, 2, 10, 17, 32, 48, 56, 69, 85, 102, 120, 127, 137, 150, 158, 169, 177, 192}
|
||||
|
||||
func (i codeBench) String() string {
|
||||
if i >= codeBench(len(_Code_index)-1) {
|
||||
return "Code(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Code_name[_Code_index[i]:_Code_index[i+1]]
|
||||
}
|
||||
|
||||
var nameMap = map[codeBench]string{
|
||||
OK: "OK",
|
||||
Canceled: "Canceled",
|
||||
Unknown: "Unknown",
|
||||
InvalidArgument: "InvalidArgument",
|
||||
DeadlineExceeded: "DeadlineExceeded",
|
||||
NotFound: "NotFound",
|
||||
AlreadyExists: "AlreadyExists",
|
||||
PermissionDenied: "PermissionDenied",
|
||||
ResourceExhausted: "ResourceExhausted",
|
||||
FailedPrecondition: "FailedPrecondition",
|
||||
Aborted: "Aborted",
|
||||
OutOfRange: "OutOfRange",
|
||||
Unimplemented: "Unimplemented",
|
||||
Internal: "Internal",
|
||||
Unavailable: "Unavailable",
|
||||
DataLoss: "DataLoss",
|
||||
Unauthenticated: "Unauthenticated",
|
||||
}
|
||||
|
||||
func (i codeBench) StringUsingMap() string {
|
||||
if s, ok := nameMap[i]; ok {
|
||||
return s
|
||||
}
|
||||
return "Code(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
|
||||
func BenchmarkCodeStringStringer(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := codeBench(uint32(i % 17))
|
||||
_ = c.String()
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
func BenchmarkCodeStringMap(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := codeBench(uint32(i % 17))
|
||||
_ = c.StringUsingMap()
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
// codes.Code.String() does a switch.
|
||||
func BenchmarkCodeStringSwitch(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := codes.Code(uint32(i % 17))
|
||||
_ = c.String()
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
// Testing all codes (0<=c<=16) and also one overflow (17).
|
||||
func BenchmarkCodeStringStringerWithOverflow(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := codeBench(uint32(i % 18))
|
||||
_ = c.String()
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
// Testing all codes (0<=c<=16) and also one overflow (17).
|
||||
func BenchmarkCodeStringSwitchWithOverflow(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c := codes.Code(uint32(i % 18))
|
||||
_ = c.String()
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
120
vendor/google.golang.org/grpc/benchmark/primitives/context_test.go
generated
vendored
Normal file
120
vendor/google.golang.org/grpc/benchmark/primitives/context_test.go
generated
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package primitives_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func BenchmarkCancelContextErrNoErr(b *testing.B) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := ctx.Err(); err != nil {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
|
||||
func BenchmarkCancelContextErrGotErr(b *testing.B) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := ctx.Err(); err == nil {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCancelContextChannelNoErr(b *testing.B) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
for i := 0; i < b.N; i++ {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
b.Fatal("error: ctx.Done():", ctx.Err())
|
||||
default:
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
|
||||
func BenchmarkCancelContextChannelGotErr(b *testing.B) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
for i := 0; i < b.N; i++ {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if err := ctx.Err(); err == nil {
|
||||
b.Fatal("error")
|
||||
}
|
||||
default:
|
||||
b.Fatal("error: !ctx.Done()")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkTimerContextErrNoErr(b *testing.B) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 24*time.Hour)
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := ctx.Err(); err != nil {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
|
||||
func BenchmarkTimerContextErrGotErr(b *testing.B) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Microsecond)
|
||||
cancel()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := ctx.Err(); err == nil {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkTimerContextChannelNoErr(b *testing.B) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 24*time.Hour)
|
||||
for i := 0; i < b.N; i++ {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
b.Fatal("error: ctx.Done():", ctx.Err())
|
||||
default:
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
|
||||
func BenchmarkTimerContextChannelGotErr(b *testing.B) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Microsecond)
|
||||
cancel()
|
||||
for i := 0; i < b.N; i++ {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if err := ctx.Err(); err == nil {
|
||||
b.Fatal("error")
|
||||
}
|
||||
default:
|
||||
b.Fatal("error: !ctx.Done()")
|
||||
}
|
||||
}
|
||||
}
|
376
vendor/google.golang.org/grpc/benchmark/primitives/primitives_test.go
generated
vendored
Normal file
376
vendor/google.golang.org/grpc/benchmark/primitives/primitives_test.go
generated
vendored
Normal file
@ -0,0 +1,376 @@
|
||||
// +build go1.7
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2017 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// Package primitives_test contains benchmarks for various synchronization primitives
|
||||
// available in Go.
|
||||
package primitives_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func BenchmarkSelectClosed(b *testing.B) {
|
||||
c := make(chan struct{})
|
||||
close(c)
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
select {
|
||||
case <-c:
|
||||
x++
|
||||
default:
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSelectOpen(b *testing.B) {
|
||||
c := make(chan struct{})
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
select {
|
||||
case <-c:
|
||||
default:
|
||||
x++
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAtomicBool(b *testing.B) {
|
||||
c := int32(0)
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if atomic.LoadInt32(&c) == 0 {
|
||||
x++
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAtomicValueLoad(b *testing.B) {
|
||||
c := atomic.Value{}
|
||||
c.Store(0)
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if c.Load().(int) == 0 {
|
||||
x++
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAtomicValueStore(b *testing.B) {
|
||||
c := atomic.Value{}
|
||||
v := 123
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Store(v)
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
func BenchmarkMutex(b *testing.B) {
|
||||
c := sync.Mutex{}
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Lock()
|
||||
x++
|
||||
c.Unlock()
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRWMutex(b *testing.B) {
|
||||
c := sync.RWMutex{}
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.RLock()
|
||||
x++
|
||||
c.RUnlock()
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRWMutexW(b *testing.B) {
|
||||
c := sync.RWMutex{}
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Lock()
|
||||
x++
|
||||
c.Unlock()
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMutexWithDefer(b *testing.B) {
|
||||
c := sync.Mutex{}
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
func() {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
x++
|
||||
}()
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMutexWithClosureDefer(b *testing.B) {
|
||||
c := sync.Mutex{}
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
func() {
|
||||
c.Lock()
|
||||
defer func() { c.Unlock() }()
|
||||
x++
|
||||
}()
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMutexWithoutDefer(b *testing.B) {
|
||||
c := sync.Mutex{}
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
func() {
|
||||
c.Lock()
|
||||
x++
|
||||
c.Unlock()
|
||||
}()
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAtomicAddInt64(b *testing.B) {
|
||||
var c int64
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
atomic.AddInt64(&c, 1)
|
||||
}
|
||||
b.StopTimer()
|
||||
if c != int64(b.N) {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAtomicTimeValueStore(b *testing.B) {
|
||||
var c atomic.Value
|
||||
t := time.Now()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Store(t)
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
func BenchmarkAtomic16BValueStore(b *testing.B) {
|
||||
var c atomic.Value
|
||||
t := struct {
|
||||
a int64
|
||||
b int64
|
||||
}{
|
||||
123, 123,
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Store(t)
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
func BenchmarkAtomic32BValueStore(b *testing.B) {
|
||||
var c atomic.Value
|
||||
t := struct {
|
||||
a int64
|
||||
b int64
|
||||
c int64
|
||||
d int64
|
||||
}{
|
||||
123, 123, 123, 123,
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Store(t)
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
func BenchmarkAtomicPointerStore(b *testing.B) {
|
||||
t := 123
|
||||
var up unsafe.Pointer
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
atomic.StorePointer(&up, unsafe.Pointer(&t))
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
func BenchmarkAtomicTimePointerStore(b *testing.B) {
|
||||
t := time.Now()
|
||||
var up unsafe.Pointer
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
atomic.StorePointer(&up, unsafe.Pointer(&t))
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
func BenchmarkValueStoreWithContention(b *testing.B) {
|
||||
t := 123
|
||||
for _, n := range []int{10, 100, 1000, 10000, 100000} {
|
||||
b.Run(fmt.Sprintf("Atomic/%v", n), func(b *testing.B) {
|
||||
var wg sync.WaitGroup
|
||||
var c atomic.Value
|
||||
for i := 0; i < n; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
for j := 0; j < b.N; j++ {
|
||||
c.Store(t)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
})
|
||||
b.Run(fmt.Sprintf("AtomicStorePointer/%v", n), func(b *testing.B) {
|
||||
var wg sync.WaitGroup
|
||||
var up unsafe.Pointer
|
||||
for i := 0; i < n; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
for j := 0; j < b.N; j++ {
|
||||
atomic.StorePointer(&up, unsafe.Pointer(&t))
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
})
|
||||
b.Run(fmt.Sprintf("Mutex/%v", n), func(b *testing.B) {
|
||||
var wg sync.WaitGroup
|
||||
var c int
|
||||
mu := sync.Mutex{}
|
||||
for i := 0; i < n; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
for j := 0; j < b.N; j++ {
|
||||
mu.Lock()
|
||||
c = t
|
||||
mu.Unlock()
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
_ = c
|
||||
wg.Wait()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type myFooer struct{}
|
||||
|
||||
func (myFooer) Foo() {}
|
||||
|
||||
type fooer interface {
|
||||
Foo()
|
||||
}
|
||||
|
||||
func BenchmarkInterfaceTypeAssertion(b *testing.B) {
|
||||
// Call a separate function to avoid compiler optimizations.
|
||||
runInterfaceTypeAssertion(b, myFooer{})
|
||||
}
|
||||
|
||||
func runInterfaceTypeAssertion(b *testing.B, fer interface{}) {
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, ok := fer.(fooer); ok {
|
||||
x++
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStructTypeAssertion(b *testing.B) {
|
||||
// Call a separate function to avoid compiler optimizations.
|
||||
runStructTypeAssertion(b, myFooer{})
|
||||
}
|
||||
|
||||
func runStructTypeAssertion(b *testing.B, fer interface{}) {
|
||||
x := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, ok := fer.(myFooer); ok {
|
||||
x++
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if x != b.N {
|
||||
b.Fatal("error")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user