1 // Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
2 // Use of this source code is governed by a MIT license found in the LICENSE file.
6 // All non-std package dependencies related to testing live in this file,
7 // so porting to different environment is easy (just update functions).
14 // --- these functions are used by both benchmarks and tests
16 func deepEqual(v1, v2 interface{}) (err error) {
17 if !reflect.DeepEqual(v1, v2) {
18 err = errors.New("Not Match")
23 func approxDataSize(rv reflect.Value) (sum int) {
24 switch rk := rv.Kind(); rk {
26 case reflect.Ptr, reflect.Interface:
27 sum += int(rv.Type().Size())
28 sum += approxDataSize(rv.Elem())
30 sum += int(rv.Type().Size())
31 for j := 0; j < rv.Len(); j++ {
32 sum += approxDataSize(rv.Index(j))
35 sum += int(rv.Type().Size())
38 sum += int(rv.Type().Size())
39 for _, mk := range rv.MapKeys() {
40 sum += approxDataSize(mk)
41 sum += approxDataSize(rv.MapIndex(mk))
44 //struct size already includes the full data size.
45 //sum += int(rv.Type().Size())
46 for j := 0; j < rv.NumField(); j++ {
47 sum += approxDataSize(rv.Field(j))
51 sum += int(rv.Type().Size())