Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding gob

  • Loading branch information...
commit b21a37f3f86ca0e47f1607d91be775e3b632682e 1 parent acfa4a5
Aaron Raddon authored

Showing 1 changed file with 33 additions and 2 deletions. Show diff stats Hide diff stats

  1. +33 2 encoding_test.go
35 encoding_test.go
... ... @@ -1,7 +1,9 @@
1 1 package goperf
2 2
3 3 import (
  4 + "bytes"
4 5 "code.google.com/p/goprotobuf/proto"
  6 + "encoding/gob"
5 7 "encoding/json"
6 8 "github.com/araddon/goperf/pb"
7 9 "github.com/araddon/goperf/th"
@@ -75,6 +77,7 @@ var (
75 77 protoTw []byte
76 78 thriftTw []byte
77 79 msgpackTw []byte
  80 + gobTw bytes.Buffer
78 81 tw Tweet
79 82 twl map[string]interface{}
80 83 pbtw pb.Tweet
@@ -100,6 +103,8 @@ func init() {
100 103 //log.Println(err)
101 104 //log.Println(ptw2)
102 105 msgpackTw, _ = msgpack.Marshal(tw)
  106 + enc := gob.NewEncoder(&gobTw)
  107 + _ = enc.Encode(tw)
103 108
104 109 buf := thrift.NewTMemoryBuffer()
105 110 thbp := thrift.NewTBinaryProtocol(buf, false, true)
@@ -124,6 +129,7 @@ func BenchmarkEncodingJsonTweetStruct(b *testing.B) {
124 129 b.StartTimer()
125 130 for i := 0; i < b.N; i++ {
126 131 _, _ = json.Marshal(&tw)
  132 + //log.Println(data)
127 133 }
128 134 }
129 135
@@ -152,6 +158,31 @@ func BenchmarkDecodingJsonTweetStruct(b *testing.B) {
152 158 // BenchmarkDecodingJsonTweetStruct 2000 1137723 ns/op
153 159 // = 873/sec
154 160
  161 +func BenchmarkEncodingGobTweetStruct(b *testing.B) {
  162 + b.StartTimer()
  163 + for i := 0; i < b.N; i++ {
  164 + var bb bytes.Buffer
  165 + enc := gob.NewEncoder(&bb)
  166 + _ = enc.Encode(tw)
  167 + _ = bb.Bytes()
  168 + }
  169 +}
  170 +
  171 +// BenchmarkEncodingGobTweetStruct 20000 84273 ns/op
  172 +// = 11,866/sec
  173 +
  174 +func BenchmarkDecodingGobTweet(b *testing.B) {
  175 + b.StartTimer()
  176 + for i := 0; i < b.N; i++ {
  177 + tw := Tweet{}
  178 + dec := gob.NewDecoder(&gobTw)
  179 + _ = dec.Decode(&tw)
  180 + }
  181 +}
  182 +
  183 +// BenchmarkDecodingGobTweet 500000 3879 ns/op
  184 +// = 257,798/sec
  185 +
155 186 func BenchmarkEncodingBsonTweetStruct(b *testing.B) {
156 187 b.StartTimer()
157 188 for i := 0; i < b.N; i++ {
@@ -213,8 +244,8 @@ func BenchmarkDecodingPBTweetStruct(b *testing.B) {
213 244 }
214 245 }
215 246
216   -// BenchmarkDecodingPBTweetStruct 100000 1991 ns/op
217   -// = 51,120/sec
  247 +// BenchmarkDecodingPBTweetStruct 100000 18960 ns/op
  248 +// = 52,743/sec
218 249
219 250 func BenchmarkEncodingMPTweetStruct(b *testing.B) {
220 251 b.StartTimer()

0 comments on commit b21a37f

Please sign in to comment.
Something went wrong with that request. Please try again.