Skip to content

Commit

Permalink
Add BenchmarkSleep
Browse files Browse the repository at this point in the history
  • Loading branch information
hwsmm committed Oct 29, 2024
1 parent ba6a084 commit 4d140b9
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions osu.Framework.Benchmarks/BenchmarkSleep.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Threading;
using BenchmarkDotNet.Attributes;
using osu.Framework.Platform;
using osu.Framework.Platform.Linux.Native;
using osu.Framework.Platform.Windows.Native;

namespace osu.Framework.Benchmarks
{
public class BenchmarkSleep : BenchmarkTest
{
private INativeSleep nativeSleep = null!;

private readonly TimeSpan timeSpan = TimeSpan.FromMilliseconds(1.5);

public override void SetUp()
{
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
nativeSleep = new WindowsNativeSleep();
else if (RuntimeInfo.IsUnix && UnixNativeSleep.Available)
nativeSleep = new UnixNativeSleep();
}

[Benchmark]
public void TestThreadSleep()
{
Thread.Sleep(timeSpan);
}

[Benchmark]
public void TestNativeSleep()
{
nativeSleep.Sleep(timeSpan);
}
}
}

0 comments on commit 4d140b9

Please sign in to comment.