ext_dep_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. vmsgpack "github.com/vmihailenco/msgpack"
  17. "labix.org/v2/mgo/bson"
  18. "testing"
  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 *TestStruc) ([]byte, error) {
  27. return vmsgpack.Marshal(ts)
  28. }
  29. func fnVMsgpackDecodeFn(buf []byte, ts *TestStruc) error {
  30. return vmsgpack.Unmarshal(buf, ts)
  31. }
  32. func fnBsonEncodeFn(ts *TestStruc) ([]byte, error) {
  33. return bson.Marshal(ts)
  34. }
  35. func fnBsonDecodeFn(buf []byte, ts *TestStruc) error {
  36. return bson.Unmarshal(buf, ts)
  37. }
  38. func Benchmark__Bson_____Encode(b *testing.B) {
  39. fnBenchmarkEncode(b, "bson", fnBsonEncodeFn)
  40. }
  41. func Benchmark__Bson_____Decode(b *testing.B) {
  42. fnBenchmarkDecode(b, "bson", fnBsonEncodeFn, fnBsonDecodeFn)
  43. }
  44. func Benchmark__VMsgpack_Encode(b *testing.B) {
  45. fnBenchmarkEncode(b, "v-msgpack", fnVMsgpackEncodeFn)
  46. }
  47. func Benchmark__VMsgpack_Decode(b *testing.B) {
  48. fnBenchmarkDecode(b, "v-msgpack", fnVMsgpackEncodeFn, fnVMsgpackDecodeFn)
  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. }