Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
dotnet-version: 10.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: 10.0.x
- name: Test
run: dotnet test -c Release
# KeyValues2 depends on KeyValues2.ElementFactoryGenerator
- name: Pack
run: |
dotnet pack ElementFactoryGenerator/ElementFactoryGenerator.csproj -c Release -o out
dotnet pack Datamodel.NET/Datamodel.NET.csproj -c Release -o out
run: dotnet pack Datamodel.NET/Datamodel.NET.csproj -c Release -o out
# Kept next to the push: the issued key is only valid for an hour.
- name: NuGet login
uses: NuGet/login@v1
Expand Down
19 changes: 19 additions & 0 deletions Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<ServerGarbageCollection>false</ServerGarbageCollection>
<TieredPGO>true</TieredPGO>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Datamodel.NET\Datamodel.NET.csproj" />
<ProjectReference Include="..\Tests.VMAP\Tests.VMAP.csproj" />
</ItemGroup>

</Project>
100 changes: 100 additions & 0 deletions Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Diagnostics;
using Datamodel.Codecs;
using Tests.VMAP;
using DM = Datamodel.Datamodel;

// Measures loading a vmap as plain elements and as the typed classes of Tests/ValveMap.cs, and saving the typed model.
//
// Benchmarks [--iterations N] <file or directory>...
//
// A directory contributes every .vmap inside it, largest last. Each figure is the best of N iterations (default 1).
// "typed alloc" is the managed memory allocated by the typed load, "live heap" the managed heap that survives it.

// dots as decimal separators whatever the machine locale, so that tables can be pasted anywhere
System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

var iterations = 1;
var inputs = new List<string>();

for (var i = 0; i < args.Length; i++)
{
if (args[i] == "--iterations" && i + 1 < args.Length)
{
iterations = int.Parse(args[++i]);
continue;
}

inputs.Add(args[i]);
}

if (inputs.Count == 0)
{
Console.WriteLine("usage: Benchmarks [--iterations N] <file or directory>...");
return 1;
}

var files = inputs
.SelectMany(input => Directory.Exists(input) ? Directory.GetFiles(input, "*.vmap") : [input])
.OrderBy(file => new FileInfo(file).Length)
.ToList();

Console.WriteLine($"{"map",-26} {"file size",9} {"elements",9} | {"read file",10} {"untyped load",13} {"typed load",11} {"typed/untyped",13} | {"typed alloc",11} {"live heap",9} | {"binary save",11}");

foreach (var path in files)
{
var name = Path.GetFileName(path);
var size = new FileInfo(path).Length;

var read = Time(() => File.ReadAllBytes(path), out var bytes);

var untyped = double.MaxValue;
var typed = double.MaxValue;
var save = double.MaxValue;
long allocated = 0, heap = 0, elements = 0;

for (var i = 0; i < iterations; i++)
{
Collect();
untyped = Math.Min(untyped, Time(() => DM.Load(new MemoryStream(bytes, false), DeferredMode.Disabled), out var plain));
elements = plain.AllElements.Count;
plain.Dispose();

Collect();
var before = GC.GetTotalAllocatedBytes(true);
typed = Math.Min(typed, Time(() => DM.Load<CMapRootElement>(new MemoryStream(bytes, false), DeferredMode.Disabled), out var map));
allocated = GC.GetTotalAllocatedBytes(true) - before;
heap = GC.GetTotalMemory(true);

if (map.Root is not CMapRootElement)
{
throw new InvalidOperationException($"{name}: the root was not loaded as {nameof(CMapRootElement)}");
}

save = Math.Min(save, Time(() => { map.Save(Stream.Null, "binary", 9); return 0; }, out _));
map.Dispose();
}

Console.WriteLine($"{name,-26} {size / 1048576.0,7:F1}MB {elements,9} | {Duration(read),10} {Duration(untyped),13} {Duration(typed),11} {typed / untyped,12:F2}x | {allocated / 1048576.0,9:F0}MB {heap / 1048576.0,7:F0}MB | {Duration(save),11}");
}

return 0;

/// <summary>Milliseconds up to a tenth of a second, seconds with two decimals above.</summary>
static string Duration(double milliseconds)
{
return milliseconds < 100 ? $"{milliseconds:F0}ms" : $"{milliseconds / 1000:F2}s";
}

static double Time<T>(Func<T> action, out T result)
{
var stopwatch = Stopwatch.StartNew();
result = action();
return stopwatch.Elapsed.TotalMilliseconds;
}

static void Collect()
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
16 changes: 16 additions & 0 deletions Benchmarks/Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net10.0\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
</Project>
8 changes: 8 additions & 0 deletions Benchmarks/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Benchmarks": {
"commandName": "Project",
"commandLineArgs": "--iterations 1 \"E:\\Steam\\steamapps\\common\\Counter-Strike Global Offensive\\content\\csgo_addons\\decomp_mesh_test_2\\maps\""
}
}
}
83 changes: 83 additions & 0 deletions Datamodel.NET.sln
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32901.215
Expand All @@ -8,31 +9,113 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElementFactoryGenerator", "ElementFactoryGenerator\ElementFactoryGenerator.csproj", "{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.VMAP", "Tests.VMAP\Tests.VMAP.csproj", "{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{7BB7432B-C6A6-4366-B351-D6DD284EC61D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Documentation|Any CPU = Documentation|Any CPU
Documentation|x64 = Documentation|x64
Documentation|x86 = Documentation|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{075743A9-B292-410C-B68F-6E6CF588D60A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Debug|x64.ActiveCfg = Debug|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Debug|x64.Build.0 = Debug|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Debug|x86.ActiveCfg = Debug|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Debug|x86.Build.0 = Debug|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Documentation|Any CPU.ActiveCfg = Release|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Documentation|Any CPU.Build.0 = Release|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Documentation|x64.ActiveCfg = Documentation|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Documentation|x64.Build.0 = Documentation|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Documentation|x86.ActiveCfg = Documentation|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Documentation|x86.Build.0 = Documentation|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Release|Any CPU.Build.0 = Release|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Release|x64.ActiveCfg = Release|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Release|x64.Build.0 = Release|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Release|x86.ActiveCfg = Release|Any CPU
{075743A9-B292-410C-B68F-6E6CF588D60A}.Release|x86.Build.0 = Release|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Debug|x64.ActiveCfg = Debug|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Debug|x64.Build.0 = Debug|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Debug|x86.ActiveCfg = Debug|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Debug|x86.Build.0 = Debug|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Documentation|x64.ActiveCfg = Documentation|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Documentation|x64.Build.0 = Documentation|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Documentation|x86.ActiveCfg = Documentation|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Documentation|x86.Build.0 = Documentation|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Release|Any CPU.Build.0 = Release|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Release|x64.ActiveCfg = Release|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Release|x64.Build.0 = Release|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Release|x86.ActiveCfg = Release|Any CPU
{4C928D60-5E48-4C0D-9C7E-C75D9734CD58}.Release|x86.Build.0 = Release|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Debug|x64.ActiveCfg = Debug|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Debug|x64.Build.0 = Debug|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Debug|x86.ActiveCfg = Debug|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Debug|x86.Build.0 = Debug|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Documentation|Any CPU.ActiveCfg = Release|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Documentation|Any CPU.Build.0 = Release|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Documentation|x64.ActiveCfg = Documentation|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Documentation|x64.Build.0 = Documentation|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Documentation|x86.ActiveCfg = Documentation|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Documentation|x86.Build.0 = Documentation|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Release|Any CPU.Build.0 = Release|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Release|x64.ActiveCfg = Release|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Release|x64.Build.0 = Release|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Release|x86.ActiveCfg = Release|Any CPU
{FE0CDDEB-F817-0758-1DFC-A472CC81F0F3}.Release|x86.Build.0 = Release|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Debug|x64.ActiveCfg = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Debug|x64.Build.0 = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Debug|x86.ActiveCfg = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Debug|x86.Build.0 = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Documentation|x64.ActiveCfg = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Documentation|x64.Build.0 = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Documentation|x86.ActiveCfg = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Documentation|x86.Build.0 = Debug|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Release|Any CPU.Build.0 = Release|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Release|x64.ActiveCfg = Release|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Release|x64.Build.0 = Release|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Release|x86.ActiveCfg = Release|Any CPU
{A96B12D7-DC15-4A8C-A477-146B87BF7C9F}.Release|x86.Build.0 = Release|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Debug|x64.ActiveCfg = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Debug|x64.Build.0 = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Debug|x86.ActiveCfg = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Debug|x86.Build.0 = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Documentation|Any CPU.Build.0 = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Documentation|x64.ActiveCfg = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Documentation|x64.Build.0 = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Documentation|x86.ActiveCfg = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Documentation|x86.Build.0 = Debug|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Release|Any CPU.Build.0 = Release|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Release|x64.ActiveCfg = Release|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Release|x64.Build.0 = Release|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Release|x86.ActiveCfg = Release|Any CPU
{7BB7432B-C6A6-4366-B351-D6DD284EC61D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading
Loading