-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |