Skip to content
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 4 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 0 additions & 72 deletions src/benchmarks/coreclr/perflab/ThreadingPerf.cs

This file was deleted.

35 changes: 35 additions & 0 deletions src/benchmarks/corefx/System.Threading/Perf.EventWaitHandle.cs
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 src/benchmarks/corefx/System.Threading/Perf.Interlocked.cs
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)]
Copy link
Member

@jorive jorive Jul 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Categories.CoreCLR [](start = 42, length = 18)

Is this a CoreClr duplicated benchmark? nvm, I just saw the perflab tests :P #Closed

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);
}
}
}
}
29 changes: 29 additions & 0 deletions src/benchmarks/corefx/System.Threading/Perf.Lock.cs
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();
}
}
}
}
41 changes: 41 additions & 0 deletions src/benchmarks/corefx/System.Threading/Perf.Monitor.cs
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);
}
}
}
}
45 changes: 45 additions & 0 deletions src/benchmarks/corefx/System.Threading/Perf.SpinLock.cs
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();
}
}
}
}
Loading