Remove expensive TRACE logging

```
benchmark              old ns/op     new ns/op     delta
BenchmarkTooBool-4     2671          67.8          -97.46%

benchmark              old allocs     new allocs     delta
BenchmarkTooBool-4     3              1              -66.67%

benchmark              old bytes     new bytes     delta
BenchmarkTooBool-4     49            1             -97.96%
```
This commit is contained in:
Bjørn Erik Pedersen 2016-09-26 10:42:49 +02:00
parent 7c3adfba29
commit 2580bc98dc
2 changed files with 3 additions and 18 deletions

2
.gitignore vendored
View File

@ -21,3 +21,5 @@ _testmain.go
*.exe
*.test
*.bench

View File

@ -12,14 +12,11 @@ import (
"strconv"
"strings"
"time"
jww "github.com/spf13/jwalterweatherman"
)
// ToTimeE casts an empty interface to time.Time.
func ToTimeE(i interface{}) (tim time.Time, err error) {
i = indirect(i)
jww.TRACE.Println("ToTimeE called on type:", reflect.TypeOf(i))
switch s := i.(type) {
case time.Time:
@ -38,7 +35,6 @@ func ToTimeE(i interface{}) (tim time.Time, err error) {
// ToDurationE casts an empty interface to time.Duration.
func ToDurationE(i interface{}) (d time.Duration, err error) {
i = indirect(i)
jww.TRACE.Println("ToDurationE called on type:", reflect.TypeOf(i))
switch s := i.(type) {
case time.Duration:
@ -64,8 +60,8 @@ func ToDurationE(i interface{}) (d time.Duration, err error) {
// ToBoolE casts an empty interface to a bool.
func ToBoolE(i interface{}) (bool, error) {
i = indirect(i)
jww.TRACE.Println("ToBoolE called on type:", reflect.TypeOf(i))
switch b := i.(type) {
case bool:
@ -87,7 +83,6 @@ func ToBoolE(i interface{}) (bool, error) {
// ToFloat64E casts an empty interface to a float64.
func ToFloat64E(i interface{}) (float64, error) {
i = indirect(i)
jww.TRACE.Println("ToFloat64E called on type:", reflect.TypeOf(i))
switch s := i.(type) {
case float64:
@ -118,7 +113,6 @@ func ToFloat64E(i interface{}) (float64, error) {
// ToInt64E casts an empty interface to an int64.
func ToInt64E(i interface{}) (int64, error) {
i = indirect(i)
jww.TRACE.Println("ToInt64E called on type:", reflect.TypeOf(i))
switch s := i.(type) {
case int64:
@ -154,7 +148,6 @@ func ToInt64E(i interface{}) (int64, error) {
// ToIntE casts an empty interface to an int.
func ToIntE(i interface{}) (int, error) {
i = indirect(i)
jww.TRACE.Println("ToIntE called on type:", reflect.TypeOf(i))
switch s := i.(type) {
case int:
@ -229,7 +222,6 @@ func indirectToStringerOrError(a interface{}) interface{} {
// ToStringE casts an empty interface to a string.
func ToStringE(i interface{}) (string, error) {
i = indirectToStringerOrError(i)
jww.TRACE.Println("ToStringE called on type:", reflect.TypeOf(i))
switch s := i.(type) {
case string:
@ -267,7 +259,6 @@ func ToStringE(i interface{}) (string, error) {
// ToStringMapStringE casts an empty interface to a map[string]string.
func ToStringMapStringE(i interface{}) (map[string]string, error) {
jww.TRACE.Println("ToStringMapStringE called on type:", reflect.TypeOf(i))
var m = map[string]string{}
@ -296,7 +287,6 @@ func ToStringMapStringE(i interface{}) (map[string]string, error) {
// ToStringMapStringSliceE casts an empty interface to a map[string][]string.
func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) {
jww.TRACE.Println("ToStringMapStringSliceE called on type:", reflect.TypeOf(i))
var m = map[string][]string{}
@ -359,7 +349,6 @@ func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) {
// ToStringMapBoolE casts an empty interface to a map[string]bool.
func ToStringMapBoolE(i interface{}) (map[string]bool, error) {
jww.TRACE.Println("ToStringMapBoolE called on type:", reflect.TypeOf(i))
var m = map[string]bool{}
@ -383,7 +372,6 @@ func ToStringMapBoolE(i interface{}) (map[string]bool, error) {
// ToStringMapE casts an empty interface to a map[string]interface{}.
func ToStringMapE(i interface{}) (map[string]interface{}, error) {
jww.TRACE.Println("ToStringMapE called on type:", reflect.TypeOf(i))
var m = map[string]interface{}{}
@ -402,7 +390,6 @@ func ToStringMapE(i interface{}) (map[string]interface{}, error) {
// ToSliceE casts an empty interface to a []interface{}.
func ToSliceE(i interface{}) ([]interface{}, error) {
jww.TRACE.Println("ToSliceE called on type:", reflect.TypeOf(i))
var s []interface{}
@ -424,7 +411,6 @@ func ToSliceE(i interface{}) ([]interface{}, error) {
// ToBoolSliceE casts an empty interface to a []bool.
func ToBoolSliceE(i interface{}) ([]bool, error) {
jww.DEBUG.Println("ToBoolSliceE called on type:", reflect.TypeOf(i))
if i == nil {
return []bool{}, fmt.Errorf("Unable to Cast %#v to []bool", i)
@ -453,10 +439,8 @@ func ToBoolSliceE(i interface{}) ([]bool, error) {
}
}
// ToStringSliceE casts an empty interface to a []string.
func ToStringSliceE(i interface{}) ([]string, error) {
jww.TRACE.Println("ToStringSliceE called on type:", reflect.TypeOf(i))
var a []string
@ -483,7 +467,6 @@ func ToStringSliceE(i interface{}) ([]string, error) {
// ToIntSliceE casts an empty interface to a []int.
func ToIntSliceE(i interface{}) ([]int, error) {
jww.TRACE.Println("ToIntSliceE called on type:", reflect.TypeOf(i))
if i == nil {
return []int{}, fmt.Errorf("Unable to Cast %#v to []int", i)