Skip to content

Commit f79fd69

Browse files
authored
Detect windows OS before native windows call in ThroughputAnalysis (#484)
1 parent b3891ea commit f79fd69

15 files changed

+85
-29
lines changed

BitFaster.Caching.Benchmarks/BitFaster.Caching.Benchmarks.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>net48;net6.0</TargetFrameworks>
66
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
7+
<!-- https://stackoverflow.com/a/59916801/131345 -->
8+
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
9+
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
10+
<IsMacOS Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOS>
711
</PropertyGroup>
812

913
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -26,4 +30,14 @@
2630
<ProjectReference Include="..\BitFaster.Caching\BitFaster.Caching.csproj" />
2731
</ItemGroup>
2832

33+
<PropertyGroup Condition="'$(IsWindows)'=='true'">
34+
<DefineConstants>Windows</DefineConstants>
35+
</PropertyGroup>
36+
<PropertyGroup Condition="'$(IsLinux)'=='true'">
37+
<DefineConstants>Linux</DefineConstants>
38+
</PropertyGroup>
39+
<PropertyGroup Condition="'$(IsMacOS)'=='true'">
40+
<DefineConstants>MacOS</DefineConstants>
41+
</PropertyGroup>
42+
2943
</Project>

BitFaster.Caching.Benchmarks/DataStructureBenchmarks.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
namespace BitFaster.Caching.Benchmarks
99
{
10+
#if Windows
1011
[SimpleJob(RuntimeMoniker.Net48)]
12+
#endif
1113
[SimpleJob(RuntimeMoniker.Net60)]
1214
[MemoryDiagnoser(displayGenColumns: false)]
1315
public class DataStructureBenchmarks

BitFaster.Caching.Benchmarks/DisposerBench.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ namespace BitFaster.Caching.Benchmarks
77
{
88
// Is it possible to write a class to eliminate the dispose code for types that are not IDisposable?
99
// https://github.com/dotnet/runtime/issues/4920
10+
#if Windows
11+
[DisassemblyDiagnoser(printSource: true, maxDepth: 3)]
1012
[SimpleJob(RuntimeMoniker.Net48)]
13+
#endif
1114
[SimpleJob(RuntimeMoniker.Net60)]
12-
[DisassemblyDiagnoser(printSource: true, maxDepth: 3)]
1315
[MemoryDiagnoser(displayGenColumns: false)]
1416
[HideColumns("Job", "Median", "RatioSD", "Alloc Ratio")]
1517
public class DisposerBench

BitFaster.Caching.Benchmarks/DrainBenchmarks.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
namespace BitFaster.Caching.Benchmarks
88
{
9+
#if Windows
10+
[DisassemblyDiagnoser(printSource: true, maxDepth: 3)]
911
[SimpleJob(RuntimeMoniker.Net48)]
12+
#endif
1013
[SimpleJob(RuntimeMoniker.Net60)]
11-
[DisassemblyDiagnoser(printSource: true, maxDepth: 3)]
1214
[HideColumns("Job", "Median", "RatioSD", "Alloc Ratio")]
1315
public class DrainBenchmarks
1416
{

BitFaster.Caching.Benchmarks/Lfu/LfuJustGetOrAdd.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace BitFaster.Caching.Benchmarks
1111
{
12+
#if Windows
1213
[SimpleJob(RuntimeMoniker.Net48)]
14+
#endif
1315
[SimpleJob(RuntimeMoniker.Net60)]
1416
//[DisassemblyDiagnoser(printSource: true, maxDepth: 5)]
1517
[MemoryDiagnoser(displayGenColumns: false)]

BitFaster.Caching.Benchmarks/Lru/LruAsyncGet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ namespace BitFaster.Caching.Benchmarks.Lru
99
/// <summary>
1010
/// Verify 0 allocs for GetOrAddAsync cache hits.
1111
/// </summary>
12+
#if Windows
1213
[SimpleJob(RuntimeMoniker.Net48)]
14+
#endif
1315
[SimpleJob(RuntimeMoniker.Net60)]
1416
// [DisassemblyDiagnoser(printSource: true, maxDepth: 5)] // Unstable
1517
[MemoryDiagnoser(displayGenColumns: false)]

BitFaster.Caching.Benchmarks/Lru/LruCycleBench.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ namespace BitFaster.Caching.Benchmarks.Lru
2222
//| FastConcurrentTLru | 31.70 us | 0.087 us | 0.077 us | 1.39 | 6 KB | 2.3193 | 10 KB |
2323
//| ConcurrentTLru | 31.85 us | 0.080 us | 0.071 us | 1.39 | 6 KB | 2.3193 | 10 KB |
2424
//| ClassicLru | 16.35 us | 0.091 us | 0.076 us | 0.72 | 4 KB | 3.2959 | 14 KB |
25-
[SimpleJob(RuntimeMoniker.Net48)]
26-
[SimpleJob(RuntimeMoniker.Net60)]
25+
#if Windows
2726
[DisassemblyDiagnoser(printSource: true, maxDepth: 5)]
27+
[SimpleJob(RuntimeMoniker.Net48)]
28+
#endif
29+
[SimpleJob(RuntimeMoniker.Net60)]
2830
[MemoryDiagnoser(displayGenColumns: false)]
2931
[HideColumns("Job", "Median", "RatioSD", "Alloc Ratio")]
3032
public class LruCycleBench

BitFaster.Caching.Benchmarks/Lru/LruJustGetOrAdd.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,29 @@
1010
using System.Collections.Generic;
1111

1212
namespace BitFaster.Caching.Benchmarks
13-
{
14-
//BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
15-
//Intel Xeon W-2133 CPU 3.60GHz, 1 CPU, 12 logical and 6 physical cores
16-
//.NET SDK= 6.0.100
17-
// [Host] : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
18-
// DefaultJob : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
19-
20-
21-
//| Method | Mean | Error | StdDev | Ratio | RatioSD | Code Size | Gen 0 | Allocated |
22-
//|------------------------- |-----------:|----------:|----------:|------:|--------:|----------:|-------:|----------:|
23-
//| ConcurrentDictionary | 7.868 ns | 0.0543 ns | 0.0481 ns | 1.00 | 0.00 | 1,523 B | - | - |
24-
//| FastConcurrentLru | 10.340 ns | 0.0496 ns | 0.0464 ns | 1.31 | 0.01 | 2,185 B | - | - |
25-
//| ConcurrentLru | 13.739 ns | 0.0979 ns | 0.0916 ns | 1.75 | 0.01 | 2,207 B | - | - |
26-
//| FastConcurrentTLru | 25.820 ns | 0.0933 ns | 0.0729 ns | 3.28 | 0.02 | 2,371 B | - | - |
27-
//| ConcurrentTLru | 29.732 ns | 0.1387 ns | 0.1229 ns | 3.78 | 0.03 | 2,442 B | - | - |
28-
//| ClassicLru | 49.041 ns | 0.8575 ns | 0.8021 ns | 6.23 | 0.11 | 3,013 B | - | - |
29-
//| RuntimeMemoryCacheGet | 107.769 ns | 1.1901 ns | 0.9938 ns | 13.69 | 0.15 | 49 B | 0.0074 | 32 B |
30-
//| ExtensionsMemoryCacheGet | 93.188 ns | 0.2321 ns | 0.2171 ns | 11.85 | 0.07 | 78 B | 0.0055 | 24 B |
13+
{
14+
//BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
15+
//Intel Xeon W-2133 CPU 3.60GHz, 1 CPU, 12 logical and 6 physical cores
16+
//.NET SDK= 6.0.100
17+
// [Host] : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
18+
// DefaultJob : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
19+
20+
21+
//| Method | Mean | Error | StdDev | Ratio | RatioSD | Code Size | Gen 0 | Allocated |
22+
//|------------------------- |-----------:|----------:|----------:|------:|--------:|----------:|-------:|----------:|
23+
//| ConcurrentDictionary | 7.868 ns | 0.0543 ns | 0.0481 ns | 1.00 | 0.00 | 1,523 B | - | - |
24+
//| FastConcurrentLru | 10.340 ns | 0.0496 ns | 0.0464 ns | 1.31 | 0.01 | 2,185 B | - | - |
25+
//| ConcurrentLru | 13.739 ns | 0.0979 ns | 0.0916 ns | 1.75 | 0.01 | 2,207 B | - | - |
26+
//| FastConcurrentTLru | 25.820 ns | 0.0933 ns | 0.0729 ns | 3.28 | 0.02 | 2,371 B | - | - |
27+
//| ConcurrentTLru | 29.732 ns | 0.1387 ns | 0.1229 ns | 3.78 | 0.03 | 2,442 B | - | - |
28+
//| ClassicLru | 49.041 ns | 0.8575 ns | 0.8021 ns | 6.23 | 0.11 | 3,013 B | - | - |
29+
//| RuntimeMemoryCacheGet | 107.769 ns | 1.1901 ns | 0.9938 ns | 13.69 | 0.15 | 49 B | 0.0074 | 32 B |
30+
//| ExtensionsMemoryCacheGet | 93.188 ns | 0.2321 ns | 0.2171 ns | 11.85 | 0.07 | 78 B | 0.0055 | 24 B |
31+
#if Windows
32+
[DisassemblyDiagnoser(printSource: true, maxDepth: 5)]
3133
[SimpleJob(RuntimeMoniker.Net48)]
34+
#endif
3235
[SimpleJob(RuntimeMoniker.Net60)]
33-
[DisassemblyDiagnoser(printSource: true, maxDepth: 5)]
3436
[MemoryDiagnoser(displayGenColumns: false)]
3537
// [HardwareCounters(HardwareCounter.LlcMisses, HardwareCounter.CacheMisses)] // Requires Admin https://adamsitnik.com/Hardware-Counters-Diagnoser/
3638
// [ThreadingDiagnoser] // Requires .NET Core

BitFaster.Caching.Benchmarks/Lru/LruJustTryGet.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ namespace BitFaster.Caching.Benchmarks.Lru
1919
//| ConcurrentDictionary | 4.480 ns | 0.0230 ns | 0.0204 ns | 1.00 | 0.00 | 364 B | - |
2020
//| FastConcurrentLru | 7.705 ns | 0.0343 ns | 0.0286 ns | 1.72 | 0.01 | 448 B | - |
2121
//| FastConcurrentTLru | 25.350 ns | 0.3301 ns | 0.3088 ns | 5.66 | 0.08 | 546 B | - |
22+
#if Windows
23+
[DisassemblyDiagnoser(printSource: true, maxDepth: 5)]
2224
[SimpleJob(RuntimeMoniker.Net48)]
25+
#endif
2326
[SimpleJob(RuntimeMoniker.Net60)]
24-
[DisassemblyDiagnoser(printSource: true, maxDepth: 5)]
2527
[MemoryDiagnoser(displayGenColumns: false)]
2628
[HideColumns("Job", "Median", "RatioSD", "Alloc Ratio")]
2729
public class LruJustTryGet

BitFaster.Caching.Benchmarks/Lru/LruMultiGet.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ namespace BitFaster.Caching.Benchmarks.Lru
2424
//| ConcurrentTLru | 33.733 ns | 0.6613 ns | 0.6791 ns | 4.02 | 0.09 | 3,539 B | - | - |
2525
//| ClassicLru | 52.898 ns | 0.3079 ns | 0.2404 ns | 6.30 | 0.03 | 3,021 B | - | - |
2626
//| MemoryCache | 117.075 ns | 1.7664 ns | 1.5658 ns | 13.96 | 0.18 | 94 B | 0.0073 | 32 B |
27+
#if Windows
28+
[DisassemblyDiagnoser(printSource: true, maxDepth: 5)]
2729
[SimpleJob(RuntimeMoniker.Net48)]
30+
#endif
2831
[SimpleJob(RuntimeMoniker.Net60)]
29-
[DisassemblyDiagnoser(printSource: true, maxDepth: 5)]
3032
[MemoryDiagnoser(displayGenColumns: false)]
3133
[HideColumns("Job", "Median", "RatioSD", "Alloc Ratio")]
3234
public class LruMultiGet

0 commit comments

Comments
 (0)