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
6ba3df0d
Commit
6ba3df0d
authored
Nov 03, 2009
by
kenton@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add benchmarks for writing to a FileOutputStream. Patch from Evan Jones.
parent
c0abf64e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
ProtoBench.java
benchmarks/ProtoBench.java
+26
-0
No files found.
benchmarks/ProtoBench.java
View file @
6ba3df0d
...
@@ -33,12 +33,15 @@ package com.google.protocolbuffers;
...
@@ -33,12 +33,15 @@ package com.google.protocolbuffers;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.RandomAccessFile
;
import
java.io.RandomAccessFile
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
com.google.protobuf.ByteString
;
import
com.google.protobuf.ByteString
;
import
com.google.protobuf.CodedInputStream
;
import
com.google.protobuf.CodedInputStream
;
import
com.google.protobuf.CodedOutputStream
;
import
com.google.protobuf.Message
;
import
com.google.protobuf.Message
;
public
class
ProtoBench
{
public
class
ProtoBench
{
...
@@ -88,6 +91,16 @@ public class ProtoBench {
...
@@ -88,6 +91,16 @@ public class ProtoBench {
final
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
inputData
);
final
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
inputData
);
final
ByteString
inputString
=
ByteString
.
copyFrom
(
inputData
);
final
ByteString
inputString
=
ByteString
.
copyFrom
(
inputData
);
final
Message
sampleMessage
=
defaultMessage
.
newBuilderForType
().
mergeFrom
(
inputString
).
build
();
final
Message
sampleMessage
=
defaultMessage
.
newBuilderForType
().
mergeFrom
(
inputString
).
build
();
FileOutputStream
devNullTemp
=
null
;
CodedOutputStream
reuseDevNullTemp
=
null
;
try
{
devNullTemp
=
new
FileOutputStream
(
"/dev/null"
);
reuseDevNullTemp
=
CodedOutputStream
.
newInstance
(
devNullTemp
);
}
catch
(
FileNotFoundException
e
)
{
// ignore: this is probably Windows, where /dev/null does not exist
}
final
FileOutputStream
devNull
=
devNullTemp
;
final
CodedOutputStream
reuseDevNull
=
reuseDevNullTemp
;
benchmark
(
"Serialize to byte string"
,
inputData
.
length
,
new
Action
()
{
benchmark
(
"Serialize to byte string"
,
inputData
.
length
,
new
Action
()
{
public
void
execute
()
{
sampleMessage
.
toByteString
();
}
public
void
execute
()
{
sampleMessage
.
toByteString
();
}
});
});
...
@@ -99,6 +112,19 @@ public class ProtoBench {
...
@@ -99,6 +112,19 @@ public class ProtoBench {
sampleMessage
.
writeTo
(
new
ByteArrayOutputStream
());
sampleMessage
.
writeTo
(
new
ByteArrayOutputStream
());
}
}
});
});
if
(
devNull
!=
null
)
{
benchmark
(
"Serialize to /dev/null with FileOutputStream"
,
inputData
.
length
,
new
Action
()
{
public
void
execute
()
throws
IOException
{
sampleMessage
.
writeTo
(
devNull
);
}
});
benchmark
(
"Serialize to /dev/null reusing FileOutputStream"
,
inputData
.
length
,
new
Action
()
{
public
void
execute
()
throws
IOException
{
sampleMessage
.
writeTo
(
reuseDevNull
);
reuseDevNull
.
flush
();
// force the write to the OutputStream
}
});
}
benchmark
(
"Deserialize from byte string"
,
inputData
.
length
,
new
Action
()
{
benchmark
(
"Deserialize from byte string"
,
inputData
.
length
,
new
Action
()
{
public
void
execute
()
throws
IOException
{
public
void
execute
()
throws
IOException
{
defaultMessage
.
newBuilderForType
().
mergeFrom
(
inputString
).
build
();
defaultMessage
.
newBuilderForType
().
mergeFrom
(
inputString
).
build
();
...
...
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