mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-13 11:20:31 +00:00
Add/improve benchmarks
This commit is contained in:
@@ -1,22 +1,69 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using osu.Framework.Bindables;
|
||||
|
||||
namespace osu.Framework.Benchmarks
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
[WarmupCount(0)]
|
||||
[IterationCount(2)]
|
||||
public class BenchmarkBindableList
|
||||
{
|
||||
private readonly BindableList<int> list = new BindableList<int>();
|
||||
private IBindableList<int> iList => list;
|
||||
private static readonly int[] small_data = Enumerable.Range(0, 10).ToArray();
|
||||
|
||||
[Params(0, 1, 10, 20)]
|
||||
public int NumBindings { get; set; }
|
||||
|
||||
private BindableList<int>[] lists = null!;
|
||||
|
||||
[GlobalSetup]
|
||||
public void GlobalSetup()
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
list.Add(i);
|
||||
lists = new BindableList<int>[NumBindings + 1];
|
||||
|
||||
lists[0] = new BindableList<int>(Enumerable.Range(0, 10000).ToArray());
|
||||
for (int i = 1; i < lists.Length; i++)
|
||||
lists[i] = lists[i - 1].GetBoundCopy();
|
||||
lists[0].Clear();
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void Create()
|
||||
{
|
||||
setupList();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void Add()
|
||||
{
|
||||
setupList().Add(1);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void Remove()
|
||||
{
|
||||
setupList().Remove(0);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void Clear()
|
||||
{
|
||||
setupList().Clear();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void AddRange()
|
||||
{
|
||||
setupList().AddRange(small_data);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void SetIndex()
|
||||
{
|
||||
setupList()[0]++;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
@@ -24,27 +71,17 @@ namespace osu.Framework.Benchmarks
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
foreach (int val in list)
|
||||
result += val;
|
||||
}
|
||||
foreach (int val in setupList())
|
||||
result += val;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int EnumerateInterface()
|
||||
private BindableList<int> setupList()
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
foreach (int val in iList)
|
||||
result += val;
|
||||
}
|
||||
|
||||
return result;
|
||||
lists[0].Clear();
|
||||
lists[0].Add(0);
|
||||
return lists[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user