Tests: Add benchmarking to test stages
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -16,6 +18,22 @@ using NUnit.Framework;
|
|||||||
|
|
||||||
namespace Il2CppInspector
|
namespace Il2CppInspector
|
||||||
{
|
{
|
||||||
|
internal class Benchmark : IDisposable
|
||||||
|
{
|
||||||
|
private readonly Stopwatch timer = new Stopwatch();
|
||||||
|
private readonly string benchmarkName;
|
||||||
|
|
||||||
|
public Benchmark(string benchmarkName) {
|
||||||
|
this.benchmarkName = benchmarkName;
|
||||||
|
timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
timer.Stop();
|
||||||
|
Console.WriteLine($"{benchmarkName}: {timer.Elapsed.TotalSeconds:N2} sec");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public partial class TestRunner
|
public partial class TestRunner
|
||||||
{
|
{
|
||||||
@@ -42,7 +60,9 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
loadOptions.BinaryFilePath = testFile;
|
loadOptions.BinaryFilePath = testFile;
|
||||||
|
|
||||||
var inspectors = Il2CppInspector.LoadFromFile(testFile, testPath + @"\global-metadata.dat", loadOptions);
|
List<Il2CppInspector> inspectors;
|
||||||
|
using (new Benchmark("Load IL2CPP metadata and binary"))
|
||||||
|
inspectors = Il2CppInspector.LoadFromFile(testFile, testPath + @"\global-metadata.dat", loadOptions);
|
||||||
|
|
||||||
// If null here, there was a problem parsing the files
|
// If null here, there was a problem parsing the files
|
||||||
if (inspectors == null)
|
if (inspectors == null)
|
||||||
@@ -54,19 +74,28 @@ namespace Il2CppInspector
|
|||||||
// Dump each image in the binary separately
|
// Dump each image in the binary separately
|
||||||
|
|
||||||
Parallel.ForEach(inspectors, il2cpp => {
|
Parallel.ForEach(inspectors, il2cpp => {
|
||||||
var model = new TypeModel(il2cpp);
|
TypeModel model;
|
||||||
var appModel = new AppModel(model, makeDefaultBuild: false).Build(compiler: CppCompilerType.MSVC);
|
using (new Benchmark("Create .NET type model"))
|
||||||
|
model = new TypeModel(il2cpp);
|
||||||
|
|
||||||
|
AppModel appModel;
|
||||||
|
using (new Benchmark("Create application model"))
|
||||||
|
appModel = new AppModel(model, makeDefaultBuild: false).Build(compiler: CppCompilerType.MSVC);
|
||||||
|
|
||||||
var nameSuffix = "-" + il2cpp.BinaryImage.Arch.ToLower();
|
var nameSuffix = "-" + il2cpp.BinaryImage.Arch.ToLower();
|
||||||
|
|
||||||
|
using (new Benchmark("Create C# code stubs"))
|
||||||
new CSharpCodeStubs(model) {
|
new CSharpCodeStubs(model) {
|
||||||
ExcludedNamespaces = Constants.DefaultExcludedNamespaces,
|
ExcludedNamespaces = Constants.DefaultExcludedNamespaces,
|
||||||
SuppressMetadata = false,
|
SuppressMetadata = false,
|
||||||
MustCompile = true
|
MustCompile = true
|
||||||
}.WriteSingleFile(testPath + $@"\test-result{nameSuffix}.cs");
|
}.WriteSingleFile(testPath + $@"\test-result{nameSuffix}.cs");
|
||||||
|
|
||||||
|
using (new Benchmark("Create JSON metadata"))
|
||||||
new JSONMetadata(appModel)
|
new JSONMetadata(appModel)
|
||||||
.Write(testPath + $@"\test-result{nameSuffix}.json");
|
.Write(testPath + $@"\test-result{nameSuffix}.json");
|
||||||
|
|
||||||
|
using (new Benchmark("Create C++ scaffolding"))
|
||||||
new CppScaffolding(appModel)
|
new CppScaffolding(appModel)
|
||||||
.Write(testPath + $@"\test-cpp-result{nameSuffix}");
|
.Write(testPath + $@"\test-cpp-result{nameSuffix}");
|
||||||
|
|
||||||
@@ -78,8 +107,9 @@ namespace Il2CppInspector
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Compare test results with expected results
|
// Compare test results with expected results
|
||||||
foreach (var il2cpp in inspectors) {
|
using var _ = new Benchmark("Compare files");
|
||||||
var suffix = "-" + il2cpp.BinaryImage.Arch.ToLower();
|
for (var i = 0; i < inspectors.Count; i++) {
|
||||||
|
var suffix = (i > 0 ? "-" + i : "");
|
||||||
|
|
||||||
compareFiles(testPath, suffix + ".cs", $"test-result{suffix}.cs");
|
compareFiles(testPath, suffix + ".cs", $"test-result{suffix}.cs");
|
||||||
compareFiles(testPath, suffix + ".json", $"test-result{suffix}.json");
|
compareFiles(testPath, suffix + ".json", $"test-result{suffix}.json");
|
||||||
|
|||||||
Reference in New Issue
Block a user