Last active
June 27, 2023 10:11
-
-
Save smoogipoo/cb3b61022852bedba86472e36b1e67f7 to your computer and use it in GitHub Desktop.
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
// 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.Threading.Tasks; | |
using BenchmarkDotNet.Attributes; | |
namespace BenchmarksProject | |
{ | |
public class BenchmarkFalseSharing | |
{ | |
[Params(1, 4, 8, 16, 32, 64, 128)] | |
public int Separation { get; set; } | |
private readonly int[] data = new int[256]; | |
[Benchmark] | |
public void FalseSharing() | |
{ | |
Parallel.Invoke(incX, incY); | |
void incX() | |
{ | |
for (int i = 0; i < 1_000_000; i++) | |
data[0]++; | |
} | |
void incY() | |
{ | |
for (int i = 0; i < 1_000_000; i++) | |
data[Separation]++; | |
} | |
} | |
} | |
} |
Author
smoogipoo
commented
Jun 27, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment