Files
nats-server/server/util_test.go
Derek Collison cd56514808 pass by address
2014-04-25 13:18:50 -06:00

52 lines
764 B
Go

// Copyright 2014 Apcera Inc. All rights reserved.
package server
import (
"strconv"
"sync"
"testing"
)
func BenchmarkParseInt(b *testing.B) {
b.SetBytes(1)
n := "12345678"
for i := 0; i < b.N; i++ {
strconv.ParseInt(n, 10, 0)
}
}
func BenchmarkParseSize(b *testing.B) {
b.SetBytes(1)
n := []byte("12345678")
for i := 0; i < b.N; i++ {
parseSize(n)
}
}
func deferUnlock(mu *sync.Mutex) {
mu.Lock()
defer mu.Unlock()
}
func BenchmarkDeferMutex(b *testing.B) {
var mu sync.Mutex
b.SetBytes(1)
for i := 0; i < b.N; i++ {
deferUnlock(&mu)
}
}
func noDeferUnlock(mu *sync.Mutex) {
mu.Lock()
mu.Unlock()
}
func BenchmarkNoDeferMutex(b *testing.B) {
var mu sync.Mutex
b.SetBytes(1)
for i := 0; i < b.N; i++ {
noDeferUnlock(&mu)
}
}