ext_dep_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //+build ignore
  2. // Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved.
  3. // Use of this source code is governed by a BSD-style license found in the LICENSE file.
  4. package codec
  5. // This file includes benchmarks which have dependencies on 3rdparty
  6. // packages (bson and vmihailenco/msgpack) which must be installed locally.
  7. //
  8. // To run the benchmarks including these 3rdparty packages, first
  9. // - Uncomment first line in this file (put // // in front of it)
  10. // - Get those packages:
  11. // go get github.com/vmihailenco/msgpack
  12. // go get labix.org/v2/mgo/bson
  13. // - Run:
  14. // go test -bi -bench=.
  15. import (
  16. "testing"
  17. vmsgpack "github.com/vmihailenco/msgpack"
  18. "labix.org/v2/mgo/bson"
  19. )
  20. func init() {
  21. benchCheckers = append(benchCheckers,
  22. benchChecker{"v-msgpack", fnVMsgpackEncodeFn, fnVMsgpackDecodeFn},
  23. benchChecker{"bson", fnBsonEncodeFn, fnBsonDecodeFn},
  24. )
  25. }
  26. func fnVMsgpackEncodeFn(ts interface{}) ([]byte, error) {
  27. return vmsgpack.Marshal(ts)
  28. }
  29. func fnVMsgpackDecodeFn(buf []byte, ts interface{}) error {
  30. return vmsgpack.Unmarshal(buf, ts)
  31. }
  32. func fnBsonEncodeFn(ts interface{}) ([]byte, error) {
  33. return bson.Marshal(ts)
  34. }
  35. func fnBsonDecodeFn(buf []byte, ts interface{}) error {
  36. return bson.Unmarshal(buf, ts)
  37. }
  38. func Benchmark__Bson_______Encode(b *testing.B) {
  39. fnBenchmarkEncode(b, "bson", benchTs, fnBsonEncodeFn)
  40. }
  41. func Benchmark__Bson_______Decode(b *testing.B) {
  42. fnBenchmarkDecode(b, "bson", benchTs, fnBsonEncodeFn, fnBsonDecodeFn, fnBenchNewTs)
  43. }
  44. func Benchmark__VMsgpack___Encode(b *testing.B) {
  45. fnBenchmarkEncode(b, "v-msgpack", benchTs, fnVMsgpackEncodeFn)
  46. }
  47. func Benchmark__VMsgpack___Decode(b *testing.B) {
  48. fnBenchmarkDecode(b, "v-msgpack", benchTs, fnVMsgpackEncodeFn, fnVMsgpackDecodeFn, fnBenchNewTs)
  49. }
  50. func TestMsgpackPythonGenStreams(t *testing.T) {
  51. doTestMsgpackPythonGenStreams(t)
  52. }
  53. func TestMsgpackRpcSpecGoClientToPythonSvc(t *testing.T) {
  54. doTestMsgpackRpcSpecGoClientToPythonSvc(t)
  55. }
  56. func TestMsgpackRpcSpecPythonClientToGoSvc(t *testing.T) {
  57. doTestMsgpackRpcSpecPythonClientToGoSvc(t)
  58. }