-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port System.Threading.Performance.Tests and remove duplicated benchmarks #80
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
src/benchmarks/corefx/System.Threading/Perf.EventWaitHandle.cs
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,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Benchmarks; | ||
|
||
namespace System.Threading.Tests | ||
{ | ||
[BenchmarkCategory(Categories.CoreFX)] | ||
public class Perf_EventWaitHandle | ||
{ | ||
private const int IterationCount = 100_000; | ||
|
||
private EventWaitHandle _are; | ||
|
||
[GlobalSetup] | ||
public void Setup() => _are = new EventWaitHandle(false, EventResetMode.AutoReset); | ||
|
||
[GlobalCleanup] | ||
public void Dispose() => _are.Dispose(); | ||
|
||
[Benchmark] | ||
public void Set_Reset() | ||
{ | ||
EventWaitHandle are = _are; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
are.Set(); | ||
are.Reset(); | ||
} | ||
} | ||
} | ||
} |
156 changes: 156 additions & 0 deletions
156
src/benchmarks/corefx/System.Threading/Perf.Interlocked.cs
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,156 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Benchmarks; | ||
|
||
namespace System.Threading.Tests | ||
{ | ||
[BenchmarkCategory(Categories.CoreFX, Categories.CoreCLR)] | ||
public class Perf_Interlocked | ||
{ | ||
private const int IterationCount = 10_000_000; | ||
|
||
[Benchmark] | ||
public void Increment_int() | ||
{ | ||
int location = 0; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.Increment(ref location); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Decrement_int() | ||
{ | ||
int location = 0; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.Decrement(ref location); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Increment_long() | ||
{ | ||
long location = 0; | ||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.Increment(ref location); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Decrement_long() | ||
{ | ||
long location = 0; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.Decrement(ref location); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Add_int() | ||
{ | ||
int location = 0; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.Add(ref location, 2); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Add_long() | ||
{ | ||
long location = 0; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.Add(ref location, 2); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Exchange_int() | ||
{ | ||
int location = 0; | ||
int newValue = 1; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.Exchange(ref location, newValue); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Exchange_long() | ||
{ | ||
long location = 0; | ||
long newValue = 1; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.Exchange(ref location, newValue); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void CompareExchange_int() | ||
{ | ||
int location = 0; | ||
int newValue = 1; | ||
int comparand = 0; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.CompareExchange(ref location, newValue, comparand); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void CompareExchange_long() | ||
{ | ||
long location = 0; | ||
long newValue = 1; | ||
long comparand = 0; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.CompareExchange(ref location, newValue, comparand); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void CompareExchange_object_Match() | ||
{ | ||
string location = "What?"; | ||
string newValue = "World"; | ||
string comparand = "What?"; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.CompareExchange(ref location, newValue, comparand); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void CompareExchange_object_NoMatch() | ||
{ | ||
string location = "Hello"; | ||
string newValue = "World"; | ||
string comparand = "What?"; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Interlocked.CompareExchange(ref location, newValue, comparand); | ||
} | ||
} | ||
} | ||
} |
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,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Benchmarks; | ||
|
||
namespace System.Threading.Tests | ||
{ | ||
[BenchmarkCategory(Categories.CoreFX)] | ||
public class Perf_Lock | ||
{ | ||
private const int IterationCount = 2_000_000; | ||
|
||
ReaderWriterLockSlim _rwLock = new ReaderWriterLockSlim(); | ||
|
||
[Benchmark] | ||
public void ReaderWriterLockSlimPerf() | ||
{ | ||
ReaderWriterLockSlim rwLock = _rwLock; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
rwLock.EnterReadLock(); | ||
rwLock.ExitReadLock(); | ||
} | ||
} | ||
} | ||
} |
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,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Benchmarks; | ||
|
||
namespace System.Threading.Tests | ||
{ | ||
[BenchmarkCategory(Categories.CoreFX)] | ||
public class Perf_Monitor | ||
{ | ||
private const int IterationCount = 4_000_000; | ||
|
||
object _sync = new object(); | ||
|
||
[Benchmark] | ||
public void EnterExit() | ||
{ | ||
object sync = _sync; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Monitor.Enter(sync); | ||
Monitor.Exit(sync); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void TryEnterExit() | ||
{ | ||
object sync = _sync; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
Monitor.TryEnter(sync, 0); | ||
Monitor.Exit(sync); | ||
} | ||
} | ||
} | ||
} |
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,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Benchmarks; | ||
|
||
namespace System.Threading.Tests | ||
{ | ||
[BenchmarkCategory(Categories.CoreFX)] | ||
public class Perf_SpinLock | ||
{ | ||
private const int IterationCount = 1_000_000; | ||
|
||
SpinLock _spinLock = new SpinLock(); | ||
|
||
[Benchmark] | ||
public void EnterExit() | ||
{ | ||
SpinLock spinLock = _spinLock; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
bool lockTaken = false; | ||
|
||
spinLock.Enter(ref lockTaken); | ||
spinLock.Exit(); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void TryEnterExit() | ||
{ | ||
SpinLock spinLock = _spinLock; | ||
|
||
for (int i = 0; i < IterationCount; i++) | ||
{ | ||
bool lockTaken = false; | ||
|
||
spinLock.TryEnter(0, ref lockTaken); | ||
spinLock.Exit(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a CoreClr duplicated benchmark?nvm, I just saw the perflab tests :P #Closed