-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5342 from jsternberg/gogoproto-remove
protobuf: remove gogoproto
- Loading branch information
Showing
372 changed files
with
22,885 additions
and
75,664 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package moby_buildkit_v1 //nolint:revive | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
digest "github.com/opencontainers/go-digest" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/protobuf/proto" | ||
"google.golang.org/protobuf/types/known/timestamppb" | ||
) | ||
|
||
// Buf is used to prevent the benchmark from being optimized away. | ||
var Buf []byte | ||
|
||
func BenchmarkMarshalVertex(b *testing.B) { | ||
v := sampleVertex() | ||
for i := 0; i < b.N; i++ { | ||
var err error | ||
Buf, err = proto.Marshal(v) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
func BenchmarkMarshalVertexStatus(b *testing.B) { | ||
v := sampleVertexStatus() | ||
for i := 0; i < b.N; i++ { | ||
var err error | ||
Buf, err = proto.Marshal(v) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
func BenchmarkMarshalVertexLog(b *testing.B) { | ||
v := sampleVertexLog() | ||
for i := 0; i < b.N; i++ { | ||
var err error | ||
Buf, err = proto.Marshal(v) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
var VertexOutput Vertex | ||
|
||
func BenchmarkUnmarshalVertex(b *testing.B) { | ||
v := sampleVertex() | ||
buf, err := proto.Marshal(v) | ||
require.NoError(b, err) | ||
|
||
for i := 0; i < b.N; i++ { | ||
err := proto.Unmarshal(buf, &VertexOutput) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
var VertexStatusOutput VertexStatus | ||
|
||
func BenchmarkUnmarshalVertexStatus(b *testing.B) { | ||
v := sampleVertexStatus() | ||
buf, err := proto.Marshal(v) | ||
require.NoError(b, err) | ||
|
||
for i := 0; i < b.N; i++ { | ||
err := proto.Unmarshal(buf, &VertexStatusOutput) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
var VertexLogOutput VertexLog | ||
|
||
func BenchmarkUnmarshalVertexLog(b *testing.B) { | ||
v := sampleVertexLog() | ||
buf, err := proto.Marshal(v) | ||
require.NoError(b, err) | ||
|
||
for i := 0; i < b.N; i++ { | ||
err := proto.Unmarshal(buf, &VertexLogOutput) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
func sampleVertex() *Vertex { | ||
now := time.Now() | ||
started := now.Add(-time.Minute) | ||
return &Vertex{ | ||
Digest: string(digest.FromString("abc")), | ||
Inputs: []string{ | ||
string(digest.FromString("dep1")), | ||
string(digest.FromString("dep2")), | ||
}, | ||
Name: "abc", | ||
Started: timestamppb.New(started), | ||
Completed: timestamppb.New(now), | ||
} | ||
} | ||
|
||
func sampleVertexStatus() *VertexStatus { | ||
now := time.Now() | ||
started := now.Add(-time.Minute) | ||
return &VertexStatus{ | ||
ID: "abc", | ||
Vertex: string(digest.FromString("abc")), | ||
Name: "abc", | ||
Current: 1024, | ||
Total: 1024, | ||
Timestamp: timestamppb.New(now), | ||
Started: timestamppb.New(started), | ||
Completed: timestamppb.New(now), | ||
} | ||
} | ||
|
||
func sampleVertexLog() *VertexLog { | ||
now := time.Now() | ||
return &VertexLog{ | ||
Vertex: string(digest.FromString("abc")), | ||
Timestamp: timestamppb.New(now), | ||
Stream: 1, | ||
Msg: []byte("this is a log message"), | ||
} | ||
} |
Oops, something went wrong.