| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package codec |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
) |
| 9 |
|
| 10 |
func init() { |
| 11 |
testPreInitFns = append(testPreInitFns, codecBenchPreInit) |
| 12 |
|
| 13 |
} |
| 14 |
|
| 15 |
func codecBenchPreInit() { |
| 16 |
benchCheckers = append(benchCheckers, |
| 17 |
benchChecker{"msgpack", fnMsgpackEncodeFn, fnMsgpackDecodeFn}, |
| 18 |
benchChecker{"binc", fnBincEncodeFn, fnBincDecodeFn}, |
| 19 |
benchChecker{"simple", fnSimpleEncodeFn, fnSimpleDecodeFn}, |
| 20 |
benchChecker{"cbor", fnCborEncodeFn, fnCborDecodeFn}, |
| 21 |
benchChecker{"json", fnJsonEncodeFn, fnJsonDecodeFn}, |
| 22 |
) |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
func fnMsgpackEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { |
| 28 |
return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testMsgpackH, &testMsgpackH.BasicHandle, true) |
| 29 |
} |
| 30 |
|
| 31 |
func fnMsgpackDecodeFn(buf []byte, ts interface{}) error { |
| 32 |
return testSharedCodecDecode(buf, ts, testMsgpackH, &testMsgpackH.BasicHandle, true) |
| 33 |
} |
| 34 |
|
| 35 |
func fnBincEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { |
| 36 |
return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testBincH, &testBincH.BasicHandle, true) |
| 37 |
} |
| 38 |
|
| 39 |
func fnBincDecodeFn(buf []byte, ts interface{}) error { |
| 40 |
return testSharedCodecDecode(buf, ts, testBincH, &testBincH.BasicHandle, true) |
| 41 |
} |
| 42 |
|
| 43 |
func fnSimpleEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { |
| 44 |
return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testSimpleH, &testSimpleH.BasicHandle, true) |
| 45 |
} |
| 46 |
|
| 47 |
func fnSimpleDecodeFn(buf []byte, ts interface{}) error { |
| 48 |
return testSharedCodecDecode(buf, ts, testSimpleH, &testSimpleH.BasicHandle, true) |
| 49 |
} |
| 50 |
|
| 51 |
func fnCborEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { |
| 52 |
return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testCborH, &testCborH.BasicHandle, true) |
| 53 |
} |
| 54 |
|
| 55 |
func fnCborDecodeFn(buf []byte, ts interface{}) error { |
| 56 |
return testSharedCodecDecode(buf, ts, testCborH, &testCborH.BasicHandle, true) |
| 57 |
} |
| 58 |
|
| 59 |
func fnJsonEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { |
| 60 |
return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testJsonH, &testJsonH.BasicHandle, true) |
| 61 |
} |
| 62 |
|
| 63 |
func fnJsonDecodeFn(buf []byte, ts interface{}) error { |
| 64 |
return testSharedCodecDecode(buf, ts, testJsonH, &testJsonH.BasicHandle, true) |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
func Benchmark__Msgpack____Encode(b *testing.B) { |
| 70 |
fnBenchmarkEncode(b, "msgpack", benchTs, fnMsgpackEncodeFn) |
| 71 |
} |
| 72 |
|
| 73 |
func Benchmark__Binc_______Encode(b *testing.B) { |
| 74 |
fnBenchmarkEncode(b, "binc", benchTs, fnBincEncodeFn) |
| 75 |
} |
| 76 |
|
| 77 |
func Benchmark__Simple_____Encode(b *testing.B) { |
| 78 |
fnBenchmarkEncode(b, "simple", benchTs, fnSimpleEncodeFn) |
| 79 |
} |
| 80 |
|
| 81 |
func Benchmark__Cbor_______Encode(b *testing.B) { |
| 82 |
fnBenchmarkEncode(b, "cbor", benchTs, fnCborEncodeFn) |
| 83 |
} |
| 84 |
|
| 85 |
func Benchmark__Json_______Encode(b *testing.B) { |
| 86 |
fnBenchmarkEncode(b, "json", benchTs, fnJsonEncodeFn) |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
func Benchmark__Msgpack____Decode(b *testing.B) { |
| 92 |
fnBenchmarkDecode(b, "msgpack", benchTs, fnMsgpackEncodeFn, fnMsgpackDecodeFn, fnBenchNewTs) |
| 93 |
} |
| 94 |
|
| 95 |
func Benchmark__Binc_______Decode(b *testing.B) { |
| 96 |
fnBenchmarkDecode(b, "binc", benchTs, fnBincEncodeFn, fnBincDecodeFn, fnBenchNewTs) |
| 97 |
} |
| 98 |
|
| 99 |
func Benchmark__Simple_____Decode(b *testing.B) { |
| 100 |
fnBenchmarkDecode(b, "simple", benchTs, fnSimpleEncodeFn, fnSimpleDecodeFn, fnBenchNewTs) |
| 101 |
} |
| 102 |
|
| 103 |
func Benchmark__Cbor_______Decode(b *testing.B) { |
| 104 |
fnBenchmarkDecode(b, "cbor", benchTs, fnCborEncodeFn, fnCborDecodeFn, fnBenchNewTs) |
| 105 |
} |
| 106 |
|
| 107 |
func Benchmark__Json_______Decode(b *testing.B) { |
| 108 |
fnBenchmarkDecode(b, "json", benchTs, fnJsonEncodeFn, fnJsonDecodeFn, fnBenchNewTs) |
| 109 |
} |