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 *.exe
*.test *.test
*.bench

View File

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