Show / Hide Table of Contents

Sample: IntroEnvVars

You can configure custom environment variables for the process that is running your benchmarks. One reason for doing this might be checking out how different compilation, threading, garbage collector settings affect the performance of .NET Core.

Source code

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;

namespace BenchmarkDotNet.Samples
{
    [Config(typeof(ConfigWithCustomEnvVars))]
    public class IntroEnvVars
    {
        private class ConfigWithCustomEnvVars : ManualConfig
        {
            private const string JitNoInline = "COMPlus_JitNoInline";

            public ConfigWithCustomEnvVars()
            {
                AddJob(Job.Default.WithRuntime(CoreRuntime.Core21).WithId("Inlining enabled"));
                AddJob(Job.Default.WithRuntime(CoreRuntime.Core21)
                    .WithEnvironmentVariables(new EnvironmentVariable(JitNoInline, "1"))
                    .WithId("Inlining disabled"));
            }
        }

        [Benchmark]
        public void Foo()
        {
            // Benchmark body
        }
    }
}

Links

  • Customizing Runtime
  • Configs
  • Jobs
  • The permanent link to this sample: Sample: IntroEnvVars

  • Improve this Doc
In This Article
Back to top Copyright © 2013–2023 .NET Foundation and contributors