Skip to content

Commit

Permalink
playground update
Browse files Browse the repository at this point in the history
  • Loading branch information
NotOfficer committed Apr 2, 2024
1 parent 977f68b commit 7e3a5a7
Showing 1 changed file with 72 additions and 34 deletions.
106 changes: 72 additions & 34 deletions src/EpicManifestParser.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
using System.Net;

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;

using EpicManifestParser;
using EpicManifestParser.Api;
using EpicManifestParser.UE;

using ZlibngDotNet;

//BenchmarkDotNet.Running.BenchmarkRunner.Run<Benchmarks>();
//return;
BenchmarkDotNet.Running.BenchmarkRunner.Run<Benchmarks>();
return;

var client = new HttpClient(new HttpClientHandler
{
Expand Down Expand Up @@ -54,26 +55,21 @@
sw.Stop();
Console.WriteLine(Math.Round(sw.Elapsed.TotalMilliseconds, 0));

var testChunk = manifest.ChunkDataList[69];
var testBuffer = new byte[testChunk.WindowSize];
await testChunk.ReadDataAsync(testBuffer, manifest);
sw.Restart();
await testChunk.ReadDataAsync(testBuffer, manifest);
sw.Stop();
Console.WriteLine(Math.Round(sw.Elapsed.TotalMilliseconds, 0));

{
var fileManifest = manifest.FileManifestList.First(x =>
x.Filename.EndsWith("/pakchunk0optional-WindowsClient.ucas", StringComparison.Ordinal));
var fileManifestFileName = Path.GetFileName(fileManifest.Filename);
var fileManifestStream = fileManifest.GetStream();
var fileManifestStream = fileManifest.GetStream(false);

//await fileManifestStream.SaveFileAsync(Path.Combine(Benchmarks.DownloadsDir, "pakchunk0optional-WindowsClient.ucas"));
await fileManifestStream.SaveFileAsync(Path.Combine(Benchmarks.DownloadsDir, fileManifestFileName));

var fileBuffer = await fileManifestStream.SaveBytesAsync();
FSHAHash.TryCompute(fileBuffer, out var hash);
Console.WriteLine(hash);
FSHAHash.TryCompute(fileBuffer, out var hash1);
Console.WriteLine(hash1);

await fileManifestStream.SaveToAsync(new MemoryStream(fileBuffer, true), ProgressCallback, fileManifestFileName);
FSHAHash.TryCompute(fileBuffer, out var hash2);
Console.WriteLine(hash2);

static void ProgressCallback(SaveProgressChangedEventArgs eventArgs)
{
Expand All @@ -82,11 +78,11 @@ static void ProgressCallback(SaveProgressChangedEventArgs eventArgs)
}
}

var chunkUrl = $"http://cloudflare.epicgamescdn.com/Builds/Fortnite/CloudDir/ChunksV4/{testChunk.GroupNumber:D2}/{testChunk.Hash:X16}_{testChunk.Guid}.chunk";
Console.WriteLine(chunkUrl);
Console.ReadLine();

[MemoryDiagnoser(false)]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[MemoryDiagnoser(false), BaselineColumn]
public class Benchmarks
{
public static string DownloadsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
Expand All @@ -100,8 +96,12 @@ public class Benchmarks
private byte[] _manifestBuffer = null!;
private Zlibng _zlibng = null!;
private byte[] _manifestInfoBuffer = null!;
private FFileManifestStream _fileManifestStream = null!;
private FBuildPatchAppManifest _manifest = null!;
private FFileManifestStream _fileManifestStream1 = null!;
private FFileManifestStream _fileManifestStream2 = null!;
private byte[] _fileBuffer = null!;
private MemoryStream _fileMs = null!;
private string _filePath = null!;

[GlobalSetup]
public void Setup()
Expand All @@ -110,36 +110,74 @@ public void Setup()
_zlibng = new Zlibng(ZlibngPath);
_manifestInfoBuffer = File.ReadAllBytes(ManifestInfoPath);

var manifest = FBuildPatchAppManifest.Deserialize(_manifestBuffer, options =>
_manifest = FBuildPatchAppManifest.Deserialize(_manifestBuffer, options =>
{
options.Zlibng = _zlibng;
options.ChunkBaseUrl = "http://epicgames-download1.akamaized.net/Builds/Fortnite/CloudDir/";
//options.ChunkBaseUrl = "http://download.epicgames.com/Builds/Fortnite/CloudDir/"; // 20-21 ms
//options.ChunkBaseUrl = "http://cloudflare.epicgamescdn.com/Builds/Fortnite/CloudDir/"; // 34-36 ms
options.ChunkBaseUrl = "http://fastly-download.epicgames.com/Builds/Fortnite/CloudDir/"; // 19-20 ms
//options.ChunkBaseUrl = "http://epicgames-download1.akamaized.net/Builds/Fortnite/CloudDir/"; // 27-28 ms
options.ChunkCacheDirectory = Directory.CreateDirectory(Path.Combine(DownloadsDir, "chunks_v2")).FullName;
});
var fileManifest = manifest.FileManifestList.First(x =>
var fileManifest = _manifest.FileManifestList.First(x =>
x.Filename.EndsWith("/pakchunk0optional-WindowsClient.ucas", StringComparison.Ordinal));
_fileManifestStream = fileManifest.GetStream();
_filePath = Path.Combine(DownloadsDir, Path.GetFileName(fileManifest.Filename));
_fileBuffer = new byte[fileManifest.FileSize];
_fileMs = new MemoryStream(_fileBuffer, true);
_fileManifestStream1 = fileManifest.GetStream();
_fileManifestStream2 = fileManifest.GetStream(false);
}

[Benchmark]
public FBuildPatchAppManifest FBuildPatchAppManifest_Deserialize()
//[Benchmark]
//public FBuildPatchAppManifest FBuildPatchAppManifest_Deserialize()
//{
// return FBuildPatchAppManifest.Deserialize(_manifestBuffer, options =>
// {
// options.Zlibng = _zlibng;
// });
//}

//[Benchmark]
//public ManifestInfo? ManifestInfo_Deserialize()
//{
// return ManifestInfo.Deserialize(_manifestInfoBuffer);
//}

[BenchmarkCategory("Buffer"), Benchmark(Baseline = true)]
public async Task FFileManifestStream_SaveBuffer()
{
return FBuildPatchAppManifest.Deserialize(_manifestBuffer, options =>
{
options.Zlibng = _zlibng;
});
await _fileManifestStream2.SaveBytesAsync(_fileBuffer);
}

[BenchmarkCategory("Buffer"), Benchmark]
public async Task FFileManifestStream_SaveBuffer_AsIs()
{
await _fileManifestStream1.SaveBytesAsync(_fileBuffer);
}

[BenchmarkCategory("File"), Benchmark(Baseline = true)]
public async Task FFileManifestStream_SaveFile()
{
await _fileManifestStream2.SaveFileAsync(_filePath);
}

[BenchmarkCategory("File"), Benchmark]
public async Task FFileManifestStream_SaveFile_AsIs()
{
await _fileManifestStream1.SaveFileAsync(_filePath);
}

[Benchmark]
public ManifestInfo? ManifestInfo_Deserialize()
[BenchmarkCategory("Stream"), Benchmark(Baseline = true)]
public async Task FFileManifestStream_SaveStream()
{
return ManifestInfo.Deserialize(_manifestInfoBuffer);
_fileMs.Position = 0;
await _fileManifestStream2.SaveToAsync(_fileMs);
}

[Benchmark]
public async Task FFileManifestStream_Save()
[BenchmarkCategory("Stream"), Benchmark]
public async Task FFileManifestStream_SaveStream_AsIs()
{
await _fileManifestStream.SaveBytesAsync(_fileBuffer);
_fileMs.Position = 0;
await _fileManifestStream1.SaveToAsync(_fileMs);
}
}

0 comments on commit 7e3a5a7

Please sign in to comment.