From e1b28eb4591b328ddee41013b208768190f59c99 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 3 Feb 2025 18:17:45 +0900 Subject: [PATCH] Add benchmark for async disposal --- .../BenchmarkAsyncDisposal.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 osu.Framework.Benchmarks/BenchmarkAsyncDisposal.cs diff --git a/osu.Framework.Benchmarks/BenchmarkAsyncDisposal.cs b/osu.Framework.Benchmarks/BenchmarkAsyncDisposal.cs new file mode 100644 index 000000000..8fec6431c --- /dev/null +++ b/osu.Framework.Benchmarks/BenchmarkAsyncDisposal.cs @@ -0,0 +1,35 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using BenchmarkDotNet.Attributes; +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Shapes; + +namespace osu.Framework.Benchmarks +{ + [MemoryDiagnoser] + public partial class BenchmarkAsyncDisposal + { + private readonly List objects = new List(); + + [GlobalSetup] + [OneTimeSetUp] + public virtual void SetUp() + { + objects.Clear(); + for (int i = 0; i < 10000; i++) + objects.Add(new Box()); + } + + [Test] + [Benchmark] + public void Run() + { + objects.ForEach(AsyncDisposalQueue.Enqueue); + AsyncDisposalQueue.WaitForEmpty(); + } + } +}