diff --git a/samples/ZeroAlloc.Mapping.AotSmoke/Internal/AllocationGate.cs b/samples/ZeroAlloc.Mapping.AotSmoke/Internal/AllocationGate.cs deleted file mode 100644 index 4457cb6..0000000 --- a/samples/ZeroAlloc.Mapping.AotSmoke/Internal/AllocationGate.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace ZeroAlloc.Mapping.AotSmoke.Internal; - -internal static class AllocationGate -{ - public static void AssertBudget(int budgetBytes, int iterations, Action action, string label) - { - ArgumentNullException.ThrowIfNull(action); - if (iterations < 1) throw new ArgumentOutOfRangeException(nameof(iterations)); - - action(); - action(); - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - var before = GC.GetAllocatedBytesForCurrentThread(); - for (int i = 0; i < iterations; i++) action(); - var allocated = GC.GetAllocatedBytesForCurrentThread() - before; - - var perCall = allocated / iterations; - var totalBudget = (long)budgetBytes * iterations; - if (allocated > totalBudget) - { - throw new InvalidOperationException( - $"AllocationGate: {label} allocated {allocated} B total over {iterations} iterations " + - $"(~{perCall} B/call avg), budget is {budgetBytes} B/call ({totalBudget} B total). " + - "Use BenchmarkDotNet [MemoryDiagnoser] locally to find the culprit."); - } - } -} diff --git a/samples/ZeroAlloc.Mapping.AotSmoke/Program.cs b/samples/ZeroAlloc.Mapping.AotSmoke/Program.cs index 5862d70..9363c66 100644 --- a/samples/ZeroAlloc.Mapping.AotSmoke/Program.cs +++ b/samples/ZeroAlloc.Mapping.AotSmoke/Program.cs @@ -1,5 +1,5 @@ using ZeroAlloc.Mapping; -using ZeroAlloc.Mapping.AotSmoke.Internal; +using ZeroAlloc.TestHelpers; using ZeroAlloc.Results; namespace ZeroAlloc.Mapping.AotSmoke; diff --git a/samples/ZeroAlloc.Mapping.AotSmoke/ZeroAlloc.Mapping.AotSmoke.csproj b/samples/ZeroAlloc.Mapping.AotSmoke/ZeroAlloc.Mapping.AotSmoke.csproj index efb455e..98b5b21 100644 --- a/samples/ZeroAlloc.Mapping.AotSmoke/ZeroAlloc.Mapping.AotSmoke.csproj +++ b/samples/ZeroAlloc.Mapping.AotSmoke/ZeroAlloc.Mapping.AotSmoke.csproj @@ -25,4 +25,11 @@ ReferenceOutputAssembly="false" UndefineProperties="PublishAot" /> + + + + all + contentfiles;build + + diff --git a/tests/ZeroAlloc.Mapping.Tests/AllocationBudgetTests.cs b/tests/ZeroAlloc.Mapping.Tests/AllocationBudgetTests.cs index d0bad6f..205632c 100644 --- a/tests/ZeroAlloc.Mapping.Tests/AllocationBudgetTests.cs +++ b/tests/ZeroAlloc.Mapping.Tests/AllocationBudgetTests.cs @@ -1,4 +1,4 @@ -using ZeroAlloc.Mapping.AotSmoke.Internal; +using ZeroAlloc.TestHelpers; namespace ZeroAlloc.Mapping.Tests; diff --git a/tests/ZeroAlloc.Mapping.Tests/ZeroAlloc.Mapping.Tests.csproj b/tests/ZeroAlloc.Mapping.Tests/ZeroAlloc.Mapping.Tests.csproj index 20a020d..fcf322c 100644 --- a/tests/ZeroAlloc.Mapping.Tests/ZeroAlloc.Mapping.Tests.csproj +++ b/tests/ZeroAlloc.Mapping.Tests/ZeroAlloc.Mapping.Tests.csproj @@ -9,6 +9,10 @@ + + all + contentfiles;build + @@ -19,8 +23,4 @@ OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> - - -