54 lines
858 B
Go
54 lines
858 B
Go
package rest
|
|
|
|
import (
|
|
"net/http"
|
|
"pokedex/pb"
|
|
"testing"
|
|
)
|
|
|
|
type EmptyResponseWriter struct{}
|
|
|
|
func (w EmptyResponseWriter) Header() http.Header {
|
|
return nil
|
|
}
|
|
func (w EmptyResponseWriter) Write([]byte) (int, error) {
|
|
return 0, nil
|
|
}
|
|
func (w EmptyResponseWriter) WriteHeader(statusCode int) {
|
|
}
|
|
|
|
func pokeTest() *pb.Pokemons {
|
|
return &pb.Pokemons{
|
|
Entries: []*pb.Pokemon{
|
|
{
|
|
Name: "Charizard",
|
|
Weight: 124,
|
|
Moves: []*pb.Move{
|
|
{
|
|
Name: "Squirt",
|
|
Url: "https://boemklets.co",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func BenchmarkJson(b *testing.B) {
|
|
writer := EmptyResponseWriter{}
|
|
pokemon := pokeTest()
|
|
|
|
for i := 0; i <= b.N; i++ {
|
|
Json(writer, pokemon)
|
|
}
|
|
}
|
|
|
|
func BenchmarkProtoJson(b *testing.B) {
|
|
writer := EmptyResponseWriter{}
|
|
pokemon := pokeTest()
|
|
|
|
for i := 0; i <= b.N; i++ {
|
|
ProtoJson(writer, pokemon)
|
|
}
|
|
}
|