Skip to content

Commit

Permalink
Remove expensive TRACE logging
Browse files Browse the repository at this point in the history
```
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%
```
  • Loading branch information
bep committed Sep 26, 2016
1 parent 7c3adfb commit 2580bc9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ _testmain.go

*.exe
*.test

*.bench
19 changes: 1 addition & 18 deletions caste.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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{}

Expand Down Expand Up @@ -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{}

Expand Down Expand Up @@ -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{}

Expand All @@ -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{}{}

Expand All @@ -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{}

Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 2580bc9

Please sign in to comment.