Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
6d2c6a00
Commit
6d2c6a00
authored
6 years ago
by
BSBandme
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some fix
parent
4e3c4134
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
35 deletions
+36
-35
README.md
benchmarks/README.md
+9
-6
go_benchmark_test.go
benchmarks/go_benchmark_test.go
+27
-29
No files found.
benchmarks/README.md
View file @
6d2c6a00
...
...
@@ -37,17 +37,20 @@ $ sudo apt-get install python3-dev
And you also need to make sure
`pkg-config`
is installed.
### Go
Golang protobuf is under
[
golang repo
](
https://github.com/golang/protobuf
)
, you
need to install golang and golang protobuf's proto and protoc-gen-go before
running the benchmark. And we're using
[
testing package
](
https://golang.org/pkg/testing/
)
to test benchmark.
Go protobufs are maintained at
[
github.com/golang/protobuf
](
http://github.com/golang/protobuf
)
. If not done already, you need to install the
toolchain and the Go protoc-gen-go plugin for protoc.
To install protoc-gen-go, run:
To install golang protobuf proto and protoc-gen-go, you can
```
$ go get -u github.com/golang/protobuf/protoc-gen-go
$
go get -u github.com/golang/protobuf/proto
$
export PATH=$PATH:$(go env GOPATH)/bin
```
The first command installs
`protoc-gen-go`
into the
`bin`
directory in your local
`GOPATH`
.
The second command adds the
`bin`
directory to your
`PATH`
so that
`protoc`
can locate the plugin later.
### Big data
There's some optional big testing data which is not included in the directory
...
...
This diff is collapsed.
Click to expand it.
benchmarks/go_benchmark_test.go
View file @
6d2c6a00
package
main
import
(
"errors"
"io/ioutil"
"flag"
"testing"
"os"
benchmarkWrapper
"./tmp"
proto
"github.com/golang/protobuf/proto"
googleMessage1Proto3
"./tmp/datasets/google_message1/proto3"
googleMessage1Proto2
"./tmp/datasets/google_message1/proto2"
googleMessage1Proto3
"./tmp/datasets/google_message1/proto3"
googleMessage2
"./tmp/datasets/google_message2"
googleMessage3
"./tmp/datasets/google_message3"
googleMessage4
"./tmp/datasets/google_message4"
"errors"
"flag"
"github.com/golang/protobuf/proto"
"io/ioutil"
"os"
"testing"
)
// Data is returned by the Load function.
type
Data
struct
{
//
Marshalled is a slice of marshal
led protocol
// buffers. 1:1 with
Unmarshal
led.
Marshal
led
[][]
byte
//
marshaled is a slice of marsha
led protocol
// buffers. 1:1 with
unmarsha
led.
marsha
led
[][]
byte
// Unmarshal
led is a slice of unmarshal
led protocol
// buffers. 1:1 with
Marshal
led.
Unmarshal
led
[]
proto
.
Message
// Unmarshal
ed is a slice of unmarsha
led protocol
// buffers. 1:1 with
marsha
led.
unmarsha
led
[]
proto
.
Message
count
int
}
...
...
@@ -34,6 +32,7 @@ var data *Data
var
counter
int
type
GetDefaultInstanceFunction
func
()
proto
.
Message
var
getDefaultInstance
GetDefaultInstanceFunction
// This is used to getDefaultInstance for a message type.
...
...
@@ -62,25 +61,25 @@ func generateGetDefaltInstanceFunction(dataset benchmarkWrapper.BenchmarkDataset
func
TestMain
(
m
*
testing
.
M
)
{
flag
.
Parse
()
data
=
new
(
Data
)
rawData
,
err
or
:=
ioutil
.
ReadFile
(
flag
.
Arg
(
0
))
if
err
or
!=
nil
{
rawData
,
err
:=
ioutil
.
ReadFile
(
flag
.
Arg
(
0
))
if
err
!=
nil
{
panic
(
"Couldn't find file"
+
flag
.
Arg
(
0
))
}
var
dataset
benchmarkWrapper
.
BenchmarkDataset
if
err
1
:=
proto
.
Unmarshal
(
rawData
,
&
dataset
);
err1
!=
nil
{
if
err
=
proto
.
Unmarshal
(
rawData
,
&
dataset
);
err
!=
nil
{
panic
(
"The raw input data can't be parse into BenchmarkDataset message."
)
}
generateGetDefaltInstanceFunction
(
dataset
)
for
_
,
payload
:=
range
dataset
.
Payload
{
data
.
Marshalled
=
append
(
data
.
Marshal
led
,
payload
)
data
.
marshaled
=
append
(
data
.
marsha
led
,
payload
)
m
:=
getDefaultInstance
()
proto
.
Unmarshal
(
payload
,
m
)
data
.
Unmarshalled
=
append
(
data
.
Unmarshal
led
,
m
)
data
.
unmarshaled
=
append
(
data
.
unmarsha
led
,
m
)
}
data
.
count
=
len
(
data
.
Unmarshal
led
)
data
.
count
=
len
(
data
.
unmarsha
led
)
os
.
Exit
(
m
.
Run
())
}
...
...
@@ -88,10 +87,10 @@ func TestMain(m *testing.M) {
func
BenchmarkUnmarshal
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
payload
:=
data
.
Marshalled
[
counter
%
data
.
count
]
payload
:=
data
.
marshaled
[
counter
%
data
.
count
]
out
:=
getDefaultInstance
()
if
err
:=
proto
.
Unmarshal
(
payload
,
out
);
err
!=
nil
{
b
.
Fatalf
(
"can't unmarshal message %d %v"
,
counter
%
data
.
count
,
err
)
b
.
Fatalf
(
"can't unmarshal message %d %v"
,
counter
%
data
.
count
,
err
)
}
counter
++
}
...
...
@@ -100,9 +99,9 @@ func BenchmarkUnmarshal(b *testing.B) {
func
BenchmarkMarshal
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
m
:=
data
.
Unmarshalled
[
counter
%
data
.
count
]
m
:=
data
.
unmarshaled
[
counter
%
data
.
count
]
if
_
,
err
:=
proto
.
Marshal
(
m
);
err
!=
nil
{
b
.
Fatalf
(
"can't marshal message %d %+v: %v"
,
counter
%
data
.
count
,
m
,
err
)
b
.
Fatalf
(
"can't marshal message %d %+v: %v"
,
counter
%
data
.
count
,
m
,
err
)
}
counter
++
}
...
...
@@ -111,7 +110,7 @@ func BenchmarkMarshal(b *testing.B) {
func
BenchmarkSize
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
proto
.
Size
(
data
.
Unmarshalled
[
counter
%
data
.
count
])
proto
.
Size
(
data
.
unmarshaled
[
counter
%
data
.
count
])
counter
++
}
}
...
...
@@ -119,7 +118,7 @@ func BenchmarkSize(b *testing.B) {
func
BenchmarkClone
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
proto
.
Clone
(
data
.
Unmarshalled
[
counter
%
data
.
count
])
proto
.
Clone
(
data
.
unmarshaled
[
counter
%
data
.
count
])
counter
++
}
}
...
...
@@ -128,8 +127,7 @@ func BenchmarkMerge(b *testing.B) {
b
.
ReportAllocs
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
out
:=
getDefaultInstance
()
proto
.
Merge
(
out
,
data
.
Unmarshalled
[
counter
%
data
.
count
])
proto
.
Merge
(
out
,
data
.
unmarshaled
[
counter
%
data
.
count
])
counter
++
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment