Example #1
0
func BenchmarkUnpackNestingOverhead8Levels(b *testing.B) {
	type t1 struct {
		F1 uint8
	}
	type t2 struct {
		F1 t1
	}
	type t3 struct {
		F1 t2
	}
	type t4 struct {
		F1 t3
	}
	type t5 struct {
		F1 t4
	}
	type t6 struct {
		F1 t5
	}
	type t7 struct {
		F1 t6
	}
	type typ struct {
		F1 t7
	}
	intface, bytes := benchmarkUtil(typ{}, 1)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Unpack(bytes, &val)
	}
}
Example #2
0
func BenchmarkUnpackNestingOverhead1Level(b *testing.B) {
	type typ struct {
		F1 uint8
	}
	intface, bytes := benchmarkUtil(typ{}, 1)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Unpack(bytes, &val)
	}
}
Example #3
0
func BenchmarkUnpackOverflowCheckOverflow(b *testing.B) {
	type typ struct {
		F1 uint8 `gopack:"7"`
	}
	intface, bytes := benchmarkUtil(typ{}, 1)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Unpack(bytes, &val)
	}
}
Example #4
0
func BenchmarkUnpackUint8_16Fields(b *testing.B) {
	type typ struct {
		F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16 uint8
	}
	intface, bytes := benchmarkUtil(typ{}, 16)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Unpack(bytes, &val)
	}
}
Example #5
0
func BenchmarkUnpackUint8_4Fields(b *testing.B) {
	type typ struct {
		F1, F2, F3, F4 uint8
	}
	intface, bytes := benchmarkUtil(typ{}, 4)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Unpack(bytes, &val)
	}
}
Example #6
0
func BenchmarkUnpackBool8Fields(b *testing.B) {
	type typ struct {
		F1, F2, F3, F4, F5, F6, F7, F8 bool
	}
	intface, bytes := benchmarkUtil(typ{}, 1)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Unpack(bytes, val)
	}
}
Example #7
0
func BenchmarkUnpackBool1Field(b *testing.B) {
	type typ struct {
		F1 bool
	}
	intface, bytes := benchmarkUtil(typ{}, 1)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Unpack(bytes, &val)
	}
}
Example #8
0
// benchmarkUtil takes an example of the type
// (always a value; never a pointer), and the
// length in bytes required to pack the type.
// It registers packers and unpackers for the
// type and generates and returns a random
// instance of the type itself, and of a
// properly-lengthed byte slice.
func benchmarkUtil(example interface{}, numBytes int) (interface{}, []byte) {
	rand.Seed(time.Now().UnixNano())
	bytes := make([]byte, numBytes)

	typ := reflect.TypeOf(example)
	gopack.Pack(bytes, example)
	gopack.Unpack(bytes, reflect.New(typ).Interface())

	randBytes(bytes)
	val := randInstance(typ).Interface()

	return val, bytes
}
Example #9
0
func BenchmarkUnpackNestingMultiplicative2Levels(b *testing.B) {
	type t1 struct {
		F1 uint8
	}
	type typ struct {
		F1 uint8
		F2 t1
	}
	intface, bytes := benchmarkUtil(typ{}, 2)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Unpack(bytes, &val)
	}
}
Example #10
0
func BenchmarkUnpackNestingMultiplicative8Levels(b *testing.B) {
	type t1 struct {
		F1 uint8
	}
	type t2 struct {
		F1 uint8
		F2 t1
	}
	type t3 struct {
		F1 uint8
		F2 t2
	}
	type t4 struct {
		F1 uint8
		F2 t3
	}
	type t5 struct {
		F1 uint8
		F2 t4
	}
	type t6 struct {
		F1 uint8
		F2 t5
	}
	type t7 struct {
		F1 uint8
		F2 t6
	}
	type typ struct {
		F1 uint8
		F2 t7
	}
	intface, bytes := benchmarkUtil(typ{}, 8)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Unpack(bytes, &val)
	}
}