Skip to content

Error "Benchmark was built without optimization enabled" even with DontFailOnError #1442

Closed
@CaspecoMarcus

Description

@CaspecoMarcus

I have a simple .NET Framework 4.7.1 project using BenchmarkDotNet 0.12.1.

I need to benchmark in debug mode and read that I needed to add the JitOptimizationsValidator.DontFailOnError validator to stop getting this error:

Assembly PerformanceBenchmarksTwo which defines benchmarks references non-optimized Api.Models
Assembly PerformanceBenchmarksTwo which defines benchmarks is non-optimized
Benchmark was built without optimization enabled (most probably a DEBUG configuration). Please, build it in RELEASE.
If you want to debug the benchmarks, please see https://benchmarkdotnet.org/articles/guides/troubleshooting.html#debugging-benchmarks.

However, it doesn't seem to work. I can (for reasons described in #1441) not use DebugBuildConfig(), which does remove the error for me.
This is my code:

public class Program
{
    public class SimpleBenchmark
    {
        [Benchmark]
        public void MySimpleTest()
        {
            Console.WriteLine("Anything");
        }
    }

    private static void Main()
    {
        BenchmarkRunner.Run<SimpleBenchmark>(new CustomConfig());
    }

    private class CustomConfig : ManualConfig
    {
        public CustomConfig()
        {
            AddJob(new Job());
            AddValidator(JitOptimizationsValidator.DontFailOnError);
            AddLogger(ConsoleLogger.Default);
            AddColumnProvider(DefaultColumnProviders.Instance);
        }
    }
}

Thanks!

Activity

changed the title [-]Benchmark was built without optimization enabled error even with DontFailOnError[/-] [+]Error "Benchmark was built without optimization enabled" even with DontFailOnError[/+] on Apr 29, 2020
adamsitnik

adamsitnik commented on May 11, 2020

@adamsitnik
Member

Hi @Caspeco-MarcusOtterstrom

We really wanted to make sure that it's hard to achieve (to make sure that users are not ignoring this error when they run benchmarks in Debug mode by mistake) and you also need to use ConfigOptions.DisableOptimizationsValidator:

private static void Main()
{
    var config = var config = new ManualConfig()
        .WithOptions(ConfigOptions.DisableOptimizationsValidator)
        .AddValidator(JitOptimizationsValidator.DontFailOnError)
        .AddLogger(ConsoleLogger.Default)
        .AddColumnProvider(DefaultColumnProviders.Instance);

    BenchmarkRunner.Run<SimpleBenchmark>(config);
}

This should have been mentioned in the error message:

$"{Environment.NewLine}\tIf you don't, you can disable this policy by using 'config.With(ConfigOptions.DisableOptimizationsValidator)'."

Could you please provide a full error that you are getting? I want to make sure that this is printed.

CaspecoMarcus

CaspecoMarcus commented on May 11, 2020

@CaspecoMarcus
Author

Hello @adamsitnik
This is the full error message I am getting:

// Validating benchmarks:
Assembly PerformanceBenchmarks which defines benchmarks references non-optimized Api.Models
Assembly PerformanceBenchmarks which defines benchmarks references non-optimized Api.Data
Assembly PerformanceBenchmarks which defines benchmarks references non-optimized Api.Logic
Assembly PerformanceBenchmarks which defines benchmarks references non-optimized SecretsManager
Assembly PerformanceBenchmarks which defines benchmarks references non-optimized PayrollSystemEngine
Assembly PerformanceBenchmarks which defines benchmarks is non-optimized
Benchmark was built without optimization enabled (most probably a DEBUG configuration). Please, build it in RELEASE.
If you want to debug the benchmarks, please see https://benchmarkdotnet.org/articles/guides/troubleshooting.html#debugging-benchmarks.
No exporters defined, results will not be persisted.
// ***** BenchmarkRunner: Start   *****

That link does not seem to provide any information about the ConfigOptions.
But what you mentioned does work, I added this line in the constructor of my custom config, which did remove the warnings.

Options |= ConfigOptions.DisableOptimizationsValidator;

Thank you for this awesome library!

adamsitnik

adamsitnik commented on May 11, 2020

@adamsitnik
Member

@Caspeco-MarcusOtterstrom thanks!

I've sent #1454 to make sure nobody is ever missing this information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @adamsitnik@CaspecoMarcus

        Issue actions

          Error "Benchmark was built without optimization enabled" even with DontFailOnError · Issue #1442 · dotnet/BenchmarkDotNet