{"record":{"id":"8be8d030755db3a6","repo":"dotnet/BenchmarkDotNet","slug":"an-iteration-with-operations-0-detected","errorCode":null,"errorMessage":"An iteration with 'Operations == 0' detected","messagePattern":"An iteration with 'Operations == 0' detected","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs","lineNumber":267,"sourceCode":"                    var benchmark = benchmarks[i];\n\n                    powerManagementApplier.ApplyPerformancePlan(benchmark.Job.Environment.PowerPlanMode\n                        ?? benchmark.Job.ResolveValue(EnvironmentMode.PowerPlanModeCharacteristic, EnvironmentResolver.Instance).GetValueOrDefault());\n\n                    var info = buildResults[benchmark];\n                    var buildResult = info.buildResult;\n\n                    if (buildResult.IsBuildSuccess)\n                    {\n                        if (!config.Options.IsSet(ConfigOptions.KeepBenchmarkFiles))\n                            artifactsToCleanup.AddRange(buildResult.ArtifactsToCleanup);\n\n                        eventProcessor.OnStartRunBenchmark(benchmark);\n                        var report = await RunCore(benchmark, info.benchmarkId, logger, resolver, buildResult, benchmarkRunInfo.CompositeInProcessDiagnoser, cancellationToken).ConfigureAwait();\n                        eventProcessor.OnEndRunBenchmark(benchmark, report);\n\n                        if (report.AllMeasurements.Any(m => m.Operations == 0))\n                            throw new InvalidOperationException(\"An iteration with 'Operations == 0' detected\");\n                        reports.Add(report);\n                        if (report.GetResultRuns().Any())\n                        {\n                            var statistics = report.GetResultRuns().GetStatistics();\n                            var formatter = statistics.CreateNanosecondFormatter(cultureInfo);\n                            logger.WriteLineStatistic(statistics.ToString(cultureInfo, formatter));\n                        }\n\n                        if (!report.Success && config.Options.IsSet(ConfigOptions.StopOnFirstError))\n                        {\n                            stop = true;\n                        }\n                    }\n                    else\n                    {\n                        reports.Add(new BenchmarkReport(false, benchmark, buildResult, buildResult, default, default));\n\n                        if (buildResult.GenerateException != null)","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs#L249-L285","documentation":"Thrown after a benchmark run completes when any measurement in the report has Operations == 0. Each measurement should record at least one operation; a zero-operation measurement indicates the benchmark loop never executed its body, producing invalid statistics (division by zero in ops/sec). The check `report.AllMeasurements.Any(m => m.Operations == 0)` catches this.","triggerScenarios":"A benchmark method completes so quickly that the measurement engine fails to register operations, or a host-process issue causes the benchmark harness to return zero operations for one or more iterations. Can also indicate the generated host code crashed silently or the workload method was optimized away.","commonSituations":"Benchmarking extremely fast operations (sub-nanosecond) where the operation counter underflows. Using an older runtime or toolchain with measurement bugs. Process crashes or JIT issues in the host. Rare platform/timing edge cases.","solutions":["Increase the number of operations per invocation using [OperationsPerInvoke(N)] to ensure measurable operation counts.","Update BenchmarkDotNet to the latest version, as zero-operation detection bugs are often fixed in releases.","Check the benchmark report logs for host-process errors or warnings that may indicate why operations were not counted.","If benchmarking a trivial operation, wrap it in a loop inside the benchmark method body."],"exampleFix":"// before\n[Benchmark]\npublic void FastOp() { x += 1; }\n\n// after\n[Benchmark]\n[OperationsPerInvoke(1000)]\npublic void FastOp()\n{\n    for (int i = 0; i < 1000; i++)\n        x += 1;\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var summary = BenchmarkRunner.Run<MyBench>(config);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Operations == 0\"))\n{\n    // Retry with higher OperationsPerInvoke or adjust config\n    config = config.AddJob(Job.Default.WithInvocationCount(1).WithUnrollFactor(16));\n    var summary = BenchmarkRunner.Run<MyBench>(config);\n}","preventionTips":["Use [OperationsPerInvoke(N)] for very fast benchmark methods to ensure measurable operation counts.","Keep BenchmarkDotNet updated — zero-operation detection and measurement bugs are fixed over time.","Check benchmark logs for host-process errors or JIT issues that could cause silent failures.","If benchmarking trivial operations, loop the operation inside the benchmark method body."],"tags":["measurement","runtime","invalid-operation","operations-per-invoke"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}