Skip to content

Instantly share code, notes, and snippets.

@danmoseley
Created August 28, 2022 21:18
Show Gist options
  • Save danmoseley/c31bc023d6ec671efebff7352e3b3251 to your computer and use it in GitHub Desktop.
Save danmoseley/c31bc023d6ec671efebff7352e3b3251 to your computer and use it in GitHub Desktop.
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
[MemoryDiagnoser]
public class Program
{
// run as admin
public static void Main(string[] args)
{
var config = DefaultConfig.Instance
//.AddJob(Job.Default.WithRuntime(CoreRuntime.Core31).WithEnvironmentVariable("COMPlus_JitDisablePGO", "1"))
//.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60).WithEnvironmentVariable("COMPlus_JitDisablePGO", "1"))
.AddJob(Job.Default.WithRuntime(CoreRuntime.CreateForNewVersion("net7.0", ".NET 7.0")).WithEnvironmentVariable("COMPlus_JitDisablePGO", "1").AsBaseline())
.AddJob(Job.Default.WithRuntime(CoreRuntime.CreateForNewVersion("net7.0", ".NET 7.0")).WithEnvironmentVariables(new[] {new EnvironmentVariable("COMPlus_JitDisablePGO", "1"), new EnvironmentVariable("COMPlus_EnableHWIntrinsic", "0")}))
.AddJob(Job.Default.WithRuntime(CoreRuntime.CreateForNewVersion("net7.0", ".NET 7.0")).WithEnvironmentVariables(new[] {new EnvironmentVariable("COMPlus_JitDisablePGO", "1"), new EnvironmentVariable("COMPlus_EnableSSE3", "0")}))
.AddJob(Job.Default.WithRuntime(CoreRuntime.CreateForNewVersion("net7.0", ".NET 7.0")).WithEnvironmentVariables(new[] {new EnvironmentVariable("COMPlus_JitDisablePGO", "1"), new EnvironmentVariable("COMPlus_EnableAVX", "0")}))
.AddJob(Job.Default.WithRuntime(CoreRuntime.CreateForNewVersion("net7.0", ".NET 7.0")).WithEnvironmentVariables(new[] {new EnvironmentVariable("COMPlus_JitDisablePGO", "1"), new EnvironmentVariable("COMPlus_EnableAVX2", "0")}))
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60).WithEnvironmentVariable("COMPlus_JitDisablePGO", "1"))
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60).WithEnvironmentVariables(new[] { new EnvironmentVariable("COMPlus_JitDisablePGO", "1"), new EnvironmentVariable("COMPlus_EnableHWIntrinsic", "0") }))
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60).WithEnvironmentVariables(new[] { new EnvironmentVariable("COMPlus_JitDisablePGO", "1"), new EnvironmentVariable("COMPlus_EnableSSE3", "0") }))
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60).WithEnvironmentVariables(new[] { new EnvironmentVariable("COMPlus_JitDisablePGO", "1"), new EnvironmentVariable("COMPlus_EnableAVX", "0") }))
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60).WithEnvironmentVariables(new[] { new EnvironmentVariable("COMPlus_JitDisablePGO", "1"), new EnvironmentVariable("COMPlus_EnableAVX2", "0") }));
//.AddJob(Job.Default.WithRuntime(ClrRuntime.Net48).WithEnvironmentVariable("COMPlus_JitDisablePGO", "1"))
//.AddJob(Job.Default.WithRuntime(CoreRuntime.Core31).WithEnvironmentVariable("COMPlus_JitDisablePGO", "0"))
//.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60).WithEnvironmentVariable("COMPlus_JitDisablePGO", "0"))
//.AddJob(Job.Default.WithRuntime(CoreRuntime.CreateForNewVersion("net7.0", ".NET 7.0")).WithEnvironmentVariable("COMPlus_JitDisablePGO", "0").AsBaseline())
//.AddJob(Job.Default.WithRuntime(ClrRuntime.Net48).WithEnvironmentVariable("COMPlus_JitDisablePGO", "0"));
BenchmarkRunner.Run(typeof(Program).Assembly, args: args, config: config);
}
//[Benchmark(Baseline = true)]
//public DateTime DateTimeNow_NoDST() = > DateTime.Now;
const string Input =
" Whose woods these are I think I know.\n" +
" His house is in the village though;\n" +
" He will not see me stopping here\n" +
" To watch his woods fill up with snow.\n" +
" My little horse must think it queer\n" +
" To stop without a farmhouse near\n" +
" Between the woods and frozen lake\n" +
" The darkest evening of the year.\n" +
" He gives his harness bells a shake\n" +
" To ask if there is some mistake.\n" +
" The only other sound’s the sweep\n" +
" Of easy wind and downy flake.\n" +
" The woods are lovely, dark and deep,\n" +
" But I have promises to keep,\n" +
" And miles to go before I sleep,\n" +
" And miles to go before I sleep.\n";
[Benchmark]
public string Replace() => Input.Replace('I', 'U');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment