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
2772dfe8
Commit
2772dfe8
authored
Jun 08, 2011
by
csharptest
Committed by
rogerk
Jun 08, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Performance fix for float/double write bytes. Performance fix, do not use Array.Copy.
parent
0e2d144e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
16 deletions
+75
-16
Program.cs
src/ProtoBench/Program.cs
+3
-2
ByteString.cs
src/ProtocolBuffers/ByteString.cs
+3
-3
Bytes.cs
src/ProtocolBuffers/Bytes.cs
+33
-0
CodedInputStream.cs
src/ProtocolBuffers/CodedInputStream.cs
+6
-6
CodedOutputStream.cs
src/ProtocolBuffers/CodedOutputStream.cs
+28
-5
ProtocolBuffers.csproj
src/ProtocolBuffers/ProtocolBuffers.csproj
+1
-0
ProtocolBuffersLite.csproj
src/ProtocolBuffers/ProtocolBuffersLite.csproj
+1
-0
No files found.
src/ProtoBench/Program.cs
View file @
2772dfe8
...
...
@@ -87,6 +87,7 @@ namespace Google.ProtocolBuffers.ProtoBench
Console
.
Error
.
WriteLine
(
"(You can specify multiple pairs of descriptor type name and input data.)"
);
return
1
;
}
bool
success
=
true
;
for
(
int
i
=
0
;
i
<
args
.
Length
;
i
+=
2
)
{
...
...
@@ -94,7 +95,7 @@ namespace Google.ProtocolBuffers.ProtoBench
}
return
success
?
0
:
1
;
}
/// <summary>
/// Runs a single test. Error messages are displayed to Console.Error, and the return value indicates
/// general success/failure.
...
...
@@ -185,7 +186,7 @@ namespace Google.ProtocolBuffers.ProtoBench
double
first
=
(
iterations
*
dataSize
)
/
(
elapsed
.
TotalSeconds
*
1024
*
1024
);
if
(
Verbose
)
Console
.
WriteLine
(
"Round ---: Count = {1,6}, Bps = {2,8:f3}"
,
0
,
iterations
,
first
);
elapsed
=
TimeSpan
.
Zero
;
int
max
=
FastTest
?
30
:
10
0
;
int
max
=
FastTest
?
10
:
3
0
;
while
(
runs
<
max
)
{
...
...
src/ProtocolBuffers/ByteString.cs
View file @
2772dfe8
...
...
@@ -123,7 +123,7 @@ namespace Google.ProtocolBuffers
public
static
ByteString
CopyFrom
(
byte
[]
bytes
,
int
offset
,
int
count
)
{
byte
[]
portion
=
new
byte
[
count
];
Array
.
Copy
(
bytes
,
offset
,
portion
,
0
,
count
);
Bytes
.
Copy
(
bytes
,
offset
,
portion
,
0
,
count
);
return
new
ByteString
(
portion
);
}
...
...
@@ -259,9 +259,9 @@ namespace Google.ProtocolBuffers
/// <summary>
/// Copies the entire byte array to the destination array provided at the offset specified.
/// </summary>
public
void
CopyTo
(
Array
array
,
int
position
)
public
void
CopyTo
(
byte
[]
array
,
int
position
)
{
Array
.
Copy
(
bytes
,
0
,
array
,
position
,
bytes
.
Length
);
Bytes
.
Copy
(
bytes
,
0
,
array
,
position
,
bytes
.
Length
);
}
/// <summary>
...
...
src/ProtocolBuffers/Bytes.cs
0 → 100644
View file @
2772dfe8
namespace
Google.ProtocolBuffers
{
/// <summary>
/// Provides a utility routine to copy small arrays much more quickly than Buffer.BlockCopy
/// </summary>
static
class
Bytes
{
/// <summary>
/// The threshold above which you should use Buffer.BlockCopy rather than Bytes.Copy
/// </summary>
const
int
CopyThreshold
=
12
;
/// <summary>
/// Determines which copy routine to use based on the number of bytes to be copied.
/// </summary>
public
static
void
Copy
(
byte
[]
src
,
int
srcOffset
,
byte
[]
dst
,
int
dstOffset
,
int
count
)
{
if
(
count
>
CopyThreshold
)
global
::
System
.
Buffer
.
BlockCopy
(
src
,
srcOffset
,
dst
,
dstOffset
,
count
);
else
ByteCopy
(
src
,
srcOffset
,
dst
,
dstOffset
,
count
);
}
/// <summary>
/// Copyies the bytes provided with a for loop, faster when there are only a few bytes to copy
/// </summary>
public
static
void
ByteCopy
(
byte
[]
src
,
int
srcOffset
,
byte
[]
dst
,
int
dstOffset
,
int
count
)
{
int
stop
=
srcOffset
+
count
;
for
(
int
i
=
srcOffset
;
i
<
stop
;
i
++)
dst
[
dstOffset
++]
=
src
[
i
];
}
}
}
\ No newline at end of file
src/ProtocolBuffers/CodedInputStream.cs
View file @
2772dfe8
...
...
@@ -1225,7 +1225,7 @@ namespace Google.ProtocolBuffers
{
// We have all the bytes we need already.
byte
[]
bytes
=
new
byte
[
size
];
Array
.
Copy
(
buffer
,
bufferPos
,
bytes
,
0
,
size
);
Bytes
.
Copy
(
buffer
,
bufferPos
,
bytes
,
0
,
size
);
bufferPos
+=
size
;
return
bytes
;
}
...
...
@@ -1237,7 +1237,7 @@ namespace Google.ProtocolBuffers
// First copy what we have.
byte
[]
bytes
=
new
byte
[
size
];
int
pos
=
bufferSize
-
bufferPos
;
Array
.
Copy
(
buffer
,
bufferPos
,
bytes
,
0
,
pos
);
Bytes
.
Copy
(
buffer
,
bufferPos
,
bytes
,
0
,
pos
);
bufferPos
=
bufferSize
;
// We want to use RefillBuffer() and then copy from the buffer into our
...
...
@@ -1247,13 +1247,13 @@ namespace Google.ProtocolBuffers
while
(
size
-
pos
>
bufferSize
)
{
Array
.
Copy
(
buffer
,
0
,
bytes
,
pos
,
bufferSize
);
Buffer
.
Block
Copy
(
buffer
,
0
,
bytes
,
pos
,
bufferSize
);
pos
+=
bufferSize
;
bufferPos
=
bufferSize
;
RefillBuffer
(
true
);
}
Array
.
Copy
(
buffer
,
0
,
bytes
,
pos
,
size
-
pos
);
Bytes
.
Copy
(
buffer
,
0
,
bytes
,
pos
,
size
-
pos
);
bufferPos
=
size
-
pos
;
return
bytes
;
...
...
@@ -1305,12 +1305,12 @@ namespace Google.ProtocolBuffers
// Start by copying the leftover bytes from this.buffer.
int
newPos
=
originalBufferSize
-
originalBufferPos
;
Array
.
Copy
(
buffer
,
originalBufferPos
,
bytes
,
0
,
newPos
);
Bytes
.
Copy
(
buffer
,
originalBufferPos
,
bytes
,
0
,
newPos
);
// And now all the chunks.
foreach
(
byte
[]
chunk
in
chunks
)
{
Array
.
Copy
(
chunk
,
0
,
bytes
,
newPos
,
chunk
.
Length
);
Buffer
.
Block
Copy
(
chunk
,
0
,
bytes
,
newPos
,
chunk
.
Length
);
newPos
+=
chunk
.
Length
;
}
...
...
src/ProtocolBuffers/CodedOutputStream.cs
View file @
2772dfe8
...
...
@@ -38,6 +38,7 @@ using System;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.IO
;
using
System.Runtime.InteropServices
;
using
System.Text
;
using
Google.ProtocolBuffers.Descriptors
;
...
...
@@ -648,7 +649,20 @@ namespace Google.ProtocolBuffers
byte
[]
rawBytes
=
BitConverter
.
GetBytes
(
value
);
if
(!
BitConverter
.
IsLittleEndian
)
Array
.
Reverse
(
rawBytes
);
WriteRawBytes
(
rawBytes
,
0
,
8
);
if
(
limit
-
position
>=
8
)
{
buffer
[
position
++]
=
rawBytes
[
0
];
buffer
[
position
++]
=
rawBytes
[
1
];
buffer
[
position
++]
=
rawBytes
[
2
];
buffer
[
position
++]
=
rawBytes
[
3
];
buffer
[
position
++]
=
rawBytes
[
4
];
buffer
[
position
++]
=
rawBytes
[
5
];
buffer
[
position
++]
=
rawBytes
[
6
];
buffer
[
position
++]
=
rawBytes
[
7
];
}
else
WriteRawBytes
(
rawBytes
,
0
,
8
);
#else
WriteRawLittleEndian64
((
ulong
)
BitConverter
.
DoubleToInt64Bits
(
value
));
#endif
...
...
@@ -662,7 +676,16 @@ namespace Google.ProtocolBuffers
byte
[]
rawBytes
=
BitConverter
.
GetBytes
(
value
);
if
(!
BitConverter
.
IsLittleEndian
)
Array
.
Reverse
(
rawBytes
);
WriteRawBytes
(
rawBytes
,
0
,
4
);
if
(
limit
-
position
>=
4
)
{
buffer
[
position
++]
=
rawBytes
[
0
];
buffer
[
position
++]
=
rawBytes
[
1
];
buffer
[
position
++]
=
rawBytes
[
2
];
buffer
[
position
++]
=
rawBytes
[
3
];
}
else
WriteRawBytes
(
rawBytes
,
0
,
4
);
}
/// <summary>
...
...
@@ -985,7 +1008,7 @@ namespace Google.ProtocolBuffers
{
if
(
limit
-
position
>=
length
)
{
Array
.
Copy
(
value
,
offset
,
buffer
,
position
,
length
);
Bytes
.
Copy
(
value
,
offset
,
buffer
,
position
,
length
);
// We have room in the current buffer.
position
+=
length
;
}
...
...
@@ -994,7 +1017,7 @@ namespace Google.ProtocolBuffers
// Write extends past current buffer. Fill the rest of this buffer and
// flush.
int
bytesWritten
=
limit
-
position
;
Array
.
Copy
(
value
,
offset
,
buffer
,
position
,
bytesWritten
);
Bytes
.
Copy
(
value
,
offset
,
buffer
,
position
,
bytesWritten
);
offset
+=
bytesWritten
;
length
-=
bytesWritten
;
position
=
limit
;
...
...
@@ -1006,7 +1029,7 @@ namespace Google.ProtocolBuffers
if
(
length
<=
limit
)
{
// Fits in new buffer.
Array
.
Copy
(
value
,
offset
,
buffer
,
0
,
length
);
Bytes
.
Copy
(
value
,
offset
,
buffer
,
0
,
length
);
position
=
length
;
}
else
...
...
src/ProtocolBuffers/ProtocolBuffers.csproj
View file @
2772dfe8
...
...
@@ -99,6 +99,7 @@
<Compile
Include=
"AbstractMessageLite.cs"
>
<SubType>
Code
</SubType>
</Compile>
<Compile
Include=
"Bytes.cs"
/>
<Compile
Include=
"ByteString.cs"
/>
<Compile
Include=
"Collections\Enumerables.cs"
/>
<Compile
Include=
"Collections\IPopsicleList.cs"
/>
...
...
src/ProtocolBuffers/ProtocolBuffersLite.csproj
View file @
2772dfe8
...
...
@@ -78,6 +78,7 @@
<ItemGroup>
<Compile
Include=
"AbstractBuilderLite.cs"
/>
<Compile
Include=
"AbstractMessageLite.cs"
/>
<Compile
Include=
"Bytes.cs"
/>
<Compile
Include=
"CodedOutputStream.ComputeSize.cs"
/>
<Compile
Include=
"Collections\Dictionaries.cs"
/>
<Compile
Include=
"Collections\Enumerables.cs"
/>
...
...
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