generated from Nexus-Mods/NexusMods.App.Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from Nexus-Mods/better-benchmarks-and-fix-for…
…-empty-tx Fix for empty transactions + Some read benchmarks
- Loading branch information
Showing
7 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
benchmarks/NexusMods.MnemonicDB.Benchmarks/Benchmarks/ColdStartBenchmarks.cs
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,98 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet.Attributes; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using NexusMods.MnemonicDB.Abstractions.ElementComparers; | ||
using NexusMods.MnemonicDB.Abstractions.IndexSegments; | ||
using NexusMods.MnemonicDB.TestModel; | ||
using NexusMods.Paths; | ||
|
||
namespace NexusMods.MnemonicDB.Benchmarks.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class ColdStartBenchmarks : ABenchmark | ||
{ | ||
[GlobalSetup] | ||
public async ValueTask GlobalSetup() | ||
{ | ||
await InitializeAsync(); | ||
await InsertData(); | ||
} | ||
|
||
private async Task InsertData() | ||
{ | ||
foreach (var loadout in Enumerable.Range(0, 10)) | ||
{ | ||
using var tx = Connection.BeginTransaction(); | ||
var loadoutEntity = new Loadout.New(tx) | ||
{ | ||
Name = $"Loadout {loadout}" | ||
}; | ||
foreach (var mod in Enumerable.Range(0, 1000)) | ||
{ | ||
var modEntity = new Mod.New(tx) | ||
{ | ||
Name = $"Mod {mod}", | ||
Source = new System.Uri($"http://mod{mod}.com"), | ||
LoadoutId = loadoutEntity, | ||
OptionalHash = Hashing.xxHash3.Hash.FromLong(0) | ||
}; | ||
foreach (var file in Enumerable.Range(0, 100)) | ||
{ | ||
_ = new File.New(tx) | ||
{ | ||
Path = $"File {file}", | ||
ModId = modEntity, | ||
Size = Size.FromLong(file), | ||
Hash = Hashing.xxHash3.Hash.FromLong(file) | ||
}; | ||
} | ||
} | ||
await tx.Commit(); | ||
} | ||
} | ||
|
||
[IterationSetup] | ||
public void IterationSetup() | ||
{ | ||
Connection.Db.ClearIndexCache(); | ||
} | ||
|
||
[Benchmark] | ||
public Size TotalSizeEAVT() | ||
{ | ||
var loadout = Loadout.FindByName(Connection.Db, "Loadout 5").First(); | ||
var totalSize = Size.FromLong(0); | ||
|
||
foreach (var mod in loadout.Mods) | ||
{ | ||
foreach (var file in mod.Files) | ||
{ | ||
totalSize += file.Size; | ||
} | ||
} | ||
|
||
return totalSize; | ||
} | ||
|
||
|
||
[Benchmark] | ||
public Size TotalSizeAEVT() | ||
{ | ||
var loadoutId = Connection.Db.Datoms(Loadout.Name, "Loadout 5").First(); | ||
var modIds = Connection.Db.Datoms(Mod.LoadoutId, loadoutId.E).Select(e => e.E).ToHashSet(); | ||
var fileIds = Connection.Db.Datoms(File.ModId).ToLookup(d => ValueTag.Reference.Read<EntityId>(d.ValueSpan), d => d.E); | ||
var fileSizes = Connection.Db.Datoms(File.Size) | ||
.ToDictionary(d => d.E, d => Size.From(ValueTag.UInt64.Read<ulong>(d.ValueSpan))); | ||
|
||
var totalSize = Size.FromLong(0); | ||
foreach (var modId in modIds) | ||
{ | ||
foreach (var fileId in fileIds[modId]) | ||
{ | ||
totalSize += fileSizes[fileId]; | ||
} | ||
} | ||
return totalSize; | ||
} | ||
} |
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
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