Skip to content

Commit

Permalink
Added simple benchmark in Program
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryQuan committed Oct 2, 2023
1 parent 0d1f080 commit 7c8bfef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Nodsoft.WowsReplaysUnpack.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,30 @@
// Console.WriteLine($"[{GetGroupString(msg)}] {msg.EntityId} : {msg.MessageContent}");
//}

Task<UnpackedReplay>[] tasks = { };
for (int i = 0; i < 10; i++)
const int CYCLE = 20;
async Task<UnpackedReplay[]> syncTasks(bool sync)
{
tasks.Append(Task.Run(() => replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay"))));
List<UnpackedReplay> unpackedReplays = new List<UnpackedReplay>();
if (sync)
{
for (int i = 0; i < CYCLE; i++)
{
replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay"));
}
}
else
{
Parallel.ForEach(Enumerable.Range(0, CYCLE), (i) =>
{
unpackedReplays.Add(replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay")));
});
}
return unpackedReplays.ToArray();
}
await Task.WhenAll(tasks);

DateTime start = DateTime.Now;
await syncTasks(false);
Console.WriteLine(DateTime.Now - start);

var goodReplay = replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay"));
var alphaReplay = replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("press_account_alpha.wowsreplay"));
Expand Down
4 changes: 4 additions & 0 deletions Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Seek to offset 4 in the replay file (skipping the magic number)
byte[] signature = binaryReader.ReadBytes(4);
int jsonBlockCount = binaryReader.ReadInt32();

_semaphore.Release();
// Verify replay signature
if (!signature.SequenceEqual(ReplaySignature))
{
Expand All @@ -86,11 +87,13 @@ Seek to offset 4 in the replay file (skipping the magic number)
// The first block is the arena info
// Read it and create the unpacked replay model
UnpackedReplay replay = _replayController.CreateUnpackedReplay(ReadJsonBlock<ArenaInfo>(binaryReader));
_semaphore.Wait();
ReadExtraJsonBlocks(replay, binaryReader, jsonBlockCount);

MemoryStream decryptedStream = new();
Decrypt(binaryReader, decryptedStream);

_semaphore.Release();
// Initial stream and reader not used anymore
binaryReader.Dispose();

Expand All @@ -101,6 +104,7 @@ Seek to offset 4 in the replay file (skipping the magic number)
decryptedStream.Dispose();


_semaphore.Wait();
foreach (NetworkPacketBase networkPacket in _replayDataParser.ParseNetworkPackets(replayDataStream, options))
{
_replayController.HandleNetworkPacket(networkPacket, options);
Expand Down

0 comments on commit 7c8bfef

Please sign in to comment.