Ejemplo n.º 1
0
func BenchmarkPackNestingOverhead8Levels(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.Pack(bytes, val)
	}
}
Ejemplo n.º 2
0
func BenchmarkPackOverflowCheckOverflow(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.Pack(bytes, val)
	}
}
Ejemplo n.º 3
0
func BenchmarkPackNestingMultiplicative1Level(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.Pack(bytes, val)
	}
}
Ejemplo n.º 4
0
func BenchmarkPackBool8Fields(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.Pack(bytes, val)
	}
}
Ejemplo n.º 5
0
func BenchmarkPackBool1Field(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.Pack(bytes, val)
	}
}
Ejemplo n.º 6
0
func BenchmarkPackUint8_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.Pack(bytes, val)
	}
}
Ejemplo n.º 7
0
func BenchmarkPackUint8_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.Pack(bytes, val)
	}
}
Ejemplo n.º 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
}
Ejemplo n.º 9
0
func BenchmarkPackNestingOverhead2Levels(b *testing.B) {
	type t1 struct {
		F1 uint8
	}
	type typ struct {
		F1 t1
	}
	intface, bytes := benchmarkUtil(typ{}, 1)
	val := intface.(typ)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		gopack.Pack(bytes, val)
	}
}
Ejemplo n.º 10
0
func BenchmarkPackNestingMultiplicative8Levels(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.Pack(bytes, val)
	}
}