Move prettify to own file

This commit is contained in:
Alan Bernstein 2016-12-12 16:57:21 -06:00
parent d11a8e0af6
commit 7e28802ee3
2 changed files with 27 additions and 22 deletions

View file

@ -139,25 +139,3 @@ func Serial(bs ...Benchmark) Benchmark {
benchmarkers: bs,
}
}
// wrapper type to force human-readable JSON output
type PrettyDuration time.Duration
func (d PrettyDuration) MarshalJSON() ([]byte, error) {
s := time.Duration(d).String()
return []byte("\"" + s + "\""), nil
}
// Recursively replaces elements of ugly types with their pretty wrappers
func Prettify(m map[string]interface{}) map[string]interface{} {
newmap := make(map[string]interface{})
for k, v := range m {
switch v.(type) {
case time.Duration:
newmap[k] = PrettyDuration(v.(time.Duration))
default:
newmap[k] = Prettify(v.(map[string]interface{}))
}
}
return newmap
}

27
bench/prettify.go Normal file
View file

@ -0,0 +1,27 @@
package bench
import (
"time"
)
// wrapper type to force human-readable JSON output
type PrettyDuration time.Duration
func (d PrettyDuration) MarshalJSON() ([]byte, error) {
s := time.Duration(d).String()
return []byte("\"" + s + "\""), nil
}
// Recursively replaces elements of ugly types with their pretty wrappers
func Prettify(m map[string]interface{}) map[string]interface{} {
newmap := make(map[string]interface{})
for k, v := range m {
switch v.(type) {
case time.Duration:
newmap[k] = PrettyDuration(v.(time.Duration))
default:
newmap[k] = Prettify(v.(map[string]interface{}))
}
}
return newmap
}