Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
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
flatbuffers
Commits
796be328
Commit
796be328
authored
Apr 02, 2015
by
rw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Benchmarks for building and parsing 'gold' data.
Identifies alloc-heavy codepaths.
parent
468124fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
0 deletions
+122
-0
go_test.go
tests/go_test.go
+122
-0
No files found.
tests/go_test.go
View file @
796be328
...
@@ -1162,3 +1162,125 @@ func BenchmarkVtableDeduplication(b *testing.B) {
...
@@ -1162,3 +1162,125 @@ func BenchmarkVtableDeduplication(b *testing.B) {
builder
.
EndObject
()
builder
.
EndObject
()
}
}
}
}
// BenchmarkParseGold measures the speed of parsing the 'gold' data
// used throughout this test suite.
func
BenchmarkParseGold
(
b
*
testing
.
B
)
{
buf
,
offset
:=
CheckGeneratedBuild
(
b
.
Fatalf
)
monster
:=
example
.
GetRootAsMonster
(
buf
,
offset
)
// use these to prevent allocations:
reuse_pos
:=
example
.
Vec3
{}
reuse_test3
:=
example
.
Test
{}
reuse_table2
:=
flatbuffers
.
Table
{}
reuse_monster2
:=
example
.
Monster
{}
reuse_test4_0
:=
example
.
Test
{}
reuse_test4_1
:=
example
.
Test
{}
b
.
SetBytes
(
int64
(
len
(
buf
[
offset
:
])))
b
.
ReportAllocs
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
monster
.
Hp
()
monster
.
Mana
()
name
:=
monster
.
Name
()
_
=
name
[
0
]
_
=
name
[
len
(
name
)
-
1
]
monster
.
Pos
(
&
reuse_pos
)
reuse_pos
.
X
()
reuse_pos
.
Y
()
reuse_pos
.
Z
()
reuse_pos
.
Test1
()
reuse_pos
.
Test2
()
reuse_pos
.
Test3
(
&
reuse_test3
)
reuse_test3
.
A
()
reuse_test3
.
B
()
monster
.
TestType
()
monster
.
Test
(
&
reuse_table2
)
reuse_monster2
.
Init
(
reuse_table2
.
Bytes
,
reuse_table2
.
Pos
)
name2
:=
reuse_monster2
.
Name
()
_
=
name2
[
0
]
_
=
name2
[
len
(
name2
)
-
1
]
monster
.
InventoryLength
()
l
:=
monster
.
InventoryLength
()
for
i
:=
0
;
i
<
l
;
i
++
{
monster
.
Inventory
(
i
)
}
monster
.
Test4Length
()
monster
.
Test4
(
&
reuse_test4_0
,
0
)
monster
.
Test4
(
&
reuse_test4_1
,
1
)
reuse_test4_0
.
A
()
reuse_test4_0
.
B
()
reuse_test4_1
.
A
()
reuse_test4_1
.
B
()
monster
.
TestarrayofstringLength
()
str0
:=
monster
.
Testarrayofstring
(
0
)
_
=
str0
[
0
]
_
=
str0
[
len
(
str0
)
-
1
]
str1
:=
monster
.
Testarrayofstring
(
1
)
_
=
str1
[
0
]
_
=
str1
[
len
(
str1
)
-
1
]
}
}
// BenchmarkBuildGold uses generated code to build the example Monster.
func
BenchmarkBuildGold
(
b
*
testing
.
B
)
{
buf
,
offset
:=
CheckGeneratedBuild
(
b
.
Fatalf
)
bytes_length
:=
int64
(
len
(
buf
[
offset
:
]))
reuse_str
:=
"MyMonster"
reuse_test1
:=
"test1"
reuse_test2
:=
"test2"
reuse_fred
:=
"Fred"
b
.
SetBytes
(
bytes_length
)
b
.
ReportAllocs
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
bldr
:=
flatbuffers
.
NewBuilder
(
0
)
str
:=
bldr
.
CreateString
(
reuse_str
)
test1
:=
bldr
.
CreateString
(
reuse_test1
)
test2
:=
bldr
.
CreateString
(
reuse_test2
)
fred
:=
bldr
.
CreateString
(
reuse_fred
)
example
.
MonsterStartInventoryVector
(
bldr
,
5
)
bldr
.
PrependByte
(
4
)
bldr
.
PrependByte
(
3
)
bldr
.
PrependByte
(
2
)
bldr
.
PrependByte
(
1
)
bldr
.
PrependByte
(
0
)
inv
:=
bldr
.
EndVector
(
5
)
example
.
MonsterStart
(
bldr
)
example
.
MonsterAddName
(
bldr
,
fred
)
mon2
:=
example
.
MonsterEnd
(
bldr
)
example
.
MonsterStartTest4Vector
(
bldr
,
2
)
example
.
CreateTest
(
bldr
,
10
,
20
)
example
.
CreateTest
(
bldr
,
30
,
40
)
test4
:=
bldr
.
EndVector
(
2
)
example
.
MonsterStartTestarrayofstringVector
(
bldr
,
2
)
bldr
.
PrependUOffsetT
(
test2
)
bldr
.
PrependUOffsetT
(
test1
)
testArrayOfString
:=
bldr
.
EndVector
(
2
)
example
.
MonsterStart
(
bldr
)
pos
:=
example
.
CreateVec3
(
bldr
,
1.0
,
2.0
,
3.0
,
3.0
,
2
,
5
,
6
)
example
.
MonsterAddPos
(
bldr
,
pos
)
example
.
MonsterAddHp
(
bldr
,
80
)
example
.
MonsterAddName
(
bldr
,
str
)
example
.
MonsterAddInventory
(
bldr
,
inv
)
example
.
MonsterAddTestType
(
bldr
,
1
)
example
.
MonsterAddTest
(
bldr
,
mon2
)
example
.
MonsterAddTest4
(
bldr
,
test4
)
example
.
MonsterAddTestarrayofstring
(
bldr
,
testArrayOfString
)
mon
:=
example
.
MonsterEnd
(
bldr
)
bldr
.
Finish
(
mon
)
}
}
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