Пример #1
0
func init() {
	log.SetFlags(log.Ltime | log.Lshortfile)

	thtw = *th.NewThriftTweet()
	// create structs, maps by using json data to do initial population
	json.Unmarshal([]byte(jsons), &tw)
	json.Unmarshal([]byte(jsons), &pbtw)
	json.Unmarshal([]byte(jsons), &twl)
	json.Unmarshal([]byte(jsons), &thtw)
	//log.Println("pbtw\n", pbtw)
	// create by values per serialization type
	bsonTweet, _ = bson.Marshal(&tw)
	jsonTweet = []byte(jsons)
	protoTw, _ = proto.Marshal(&pbtw)
	//ptw2, err := proto.Marshal(&pbtw)
	//log.Println(err)
	//log.Println(ptw2)
	msgpackTw, _ = msgpack.Marshal(tw)
	enc := gob.NewEncoder(&gobTw)
	err := enc.Encode(tw)
	if err != nil {
		panic("error")
	}
	//log.Println(string(gobTw.Bytes()))

	buf := thrift.NewTMemoryBuffer()
	thbp := thrift.NewTBinaryProtocol(buf, false, true)
	thtw.Write(thbp)
	thriftTw = buf.Bytes()
	tw2 := th.NewThriftTweet()
	tw2.Read(thbp)

}
Пример #2
0
func BenchmarkDecodingThriftTweetStruct(b *testing.B) {

	b.StartTimer()
	tmem := thrift.NewTMemoryBuffer()
	thbp := thrift.NewTBinaryProtocol(tmem, false, true)
	for i := 0; i < b.N; i++ {
		tmem.Write(thriftTw)
		tw := th.NewThriftTweet()
		tw.Read(thbp)
	}
}
Пример #3
0
func BenchmarkEncodingThriftTweetStruct(b *testing.B) {
	b.StartTimer()
	// presumably there is a faster/better way to do this?
	tmem := thrift.NewTMemoryBuffer()
	thbp := thrift.NewTBinaryProtocol(tmem, false, true)
	for i := 0; i < b.N; i++ {
		thtw.Write(thbp)
		_ = tmem.Bytes()
		tmem.Reset()
	}
}