-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
203 changed files
with
12,220 additions
and
5,857 deletions.
There are no files selected for viewing
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,3 @@ | ||
{ | ||
"dotnet.defaultSolution": "src\\Eliot.UELib.sln" | ||
} |
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
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 |
---|---|---|
@@ -1,31 +1,135 @@ | ||
using System.IO; | ||
using UELib; | ||
using UELib.Core.Types; | ||
using BenchmarkDotNet.Attributes; | ||
using UELib; | ||
using UELib.Core; | ||
|
||
namespace Eliot.UELib.Benchmark | ||
{ | ||
public class UnrealStreamBenchmark | ||
{ | ||
private IUnrealStream _Stream; | ||
|
||
private readonly byte[] _ArchiveData = new byte[20]; | ||
private readonly IUnrealStream _Stream; | ||
|
||
private UColor _Color = new UColor(128, 64, 32, 0); | ||
private readonly long _ColorPosition; | ||
|
||
private int _CompactIndex1 = 0x40 - 1; | ||
private int _CompactIndex2 = 0x40 + (0x80 - 1); | ||
private int _CompactIndex3 = 0x40 + 0x80 + (0x80 - 1); | ||
private readonly long _CompactIndexPosition1, _CompactIndexPosition2, _CompactIndexPosition3; | ||
|
||
private string _String = "String"; | ||
private readonly long _StringPosition; | ||
|
||
public UnrealStreamBenchmark() | ||
{ | ||
// B, G, R, A; | ||
var structBuffer = new byte[] { 255, 128, 64, 80 }; | ||
var baseStream = new MemoryStream(structBuffer); | ||
_Stream = new UnrealTestStream(null, baseStream); | ||
var baseStream = new MemoryStream(_ArchiveData); | ||
var testArchive = new UnrealTestArchive(null, 100); | ||
_Stream = new UnrealTestStream(testArchive, baseStream); | ||
|
||
_CompactIndexPosition1 = _Stream.Position; | ||
_Stream.WriteIndex(_CompactIndex1); | ||
|
||
_CompactIndexPosition2 = _Stream.Position; | ||
_Stream.WriteIndex(_CompactIndex2); | ||
|
||
_CompactIndexPosition3 = _Stream.Position; | ||
_Stream.WriteIndex(_CompactIndex3); | ||
|
||
_StringPosition = _Stream.Position; | ||
_Stream.WriteString(_String); | ||
|
||
_ColorPosition = _Stream.Position; | ||
_Stream.WriteStruct(ref _Color); | ||
} | ||
|
||
[Benchmark] | ||
public void ReadCompactIndex1() | ||
{ | ||
_Stream.Position = _CompactIndexPosition1; | ||
_CompactIndex1 = _Stream.ReadIndex(); | ||
} | ||
|
||
[Benchmark] | ||
public void WriteCompactIndex1() | ||
{ | ||
_Stream.Position = _CompactIndexPosition1; | ||
_Stream.WriteIndex(_CompactIndex1); | ||
} | ||
|
||
[Benchmark] | ||
public void ReadCompactIndex2() | ||
{ | ||
_Stream.Position = _CompactIndexPosition2; | ||
_CompactIndex2 = _Stream.ReadIndex(); | ||
} | ||
|
||
[Benchmark] | ||
public void WriteCompactIndex2() | ||
{ | ||
_Stream.Position = _CompactIndexPosition2; | ||
_Stream.WriteIndex(_CompactIndex2); | ||
} | ||
|
||
[Benchmark] | ||
public void ReadCompactIndex3() | ||
{ | ||
_Stream.Position = _CompactIndexPosition3; | ||
_CompactIndex3 = _Stream.ReadIndex(); | ||
} | ||
|
||
[Benchmark] | ||
public void WriteCompactIndex3() | ||
{ | ||
_Stream.Position = _CompactIndexPosition3; | ||
_Stream.WriteIndex(_CompactIndex3); | ||
} | ||
|
||
[Benchmark] | ||
public void ReadString() | ||
{ | ||
_Stream.Position = _StringPosition; | ||
_String = _Stream.ReadString(); | ||
} | ||
|
||
[Benchmark] | ||
public void WriteString() | ||
{ | ||
_Stream.Position = _StringPosition; | ||
_Stream.WriteString(_String); | ||
} | ||
|
||
[Benchmark] | ||
public void ReadColor() | ||
{ | ||
_Stream.Position = _ColorPosition; | ||
_Stream.ReadStruct(_Color); | ||
} | ||
|
||
[Benchmark] | ||
public void WriteColor() | ||
{ | ||
_Stream.Position = _ColorPosition; | ||
_Stream.WriteStruct(ref _Color); | ||
} | ||
|
||
/// <summary> | ||
/// Verify that ReadAtomicStruct is indeed performing its purpose :) | ||
/// </summary> | ||
|
||
// So far marshal is faster! But writing is still slower | ||
// | Method | Mean | Error | StdDev | | ||
// |------------------- |---------:|---------:|---------:| | ||
// | ReadColor | 38.17 ns | 0.781 ns | 0.767 ns | | ||
// | ReadColorMarshal | 16.06 ns | 0.344 ns | 0.545 ns | | ||
[Benchmark] | ||
public void ReadColorMarshal() | ||
{ | ||
_Stream.Position = _ColorPosition; | ||
_Stream.ReadStructMarshal(out _Color); | ||
} | ||
|
||
[Benchmark] | ||
public void ReadAtomicStruct() | ||
public void WriteColorMarshal() | ||
{ | ||
var stream = _Stream; | ||
stream.Seek(0, SeekOrigin.Begin); | ||
stream.ReadAtomicStruct(out UColor color); | ||
_Stream.Position = _ColorPosition; | ||
_Stream.WriteStructMarshal(ref _Color); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.