|
1 | | -// Copyright 2026 Anthony Lloyd |
| 1 | +// Copyright 2026 Anthony Lloyd |
2 | 2 | // |
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | // you may not use this file except in compliance with the License. |
@@ -40,7 +40,6 @@ public static partial class Check |
40 | 40 | public static int Ulps = ParseEnvironmentVariableToInt("CsCheck_Ulps", 4); |
41 | 41 | /// <summary>The number of Where Gne iterations before throwing an exception.</summary> |
42 | 42 | public static int WhereLimit = ParseEnvironmentVariableToInt("CsCheck_WhereLimit", 100); |
43 | | - internal static bool IsDebug = Assembly.GetCallingAssembly().GetCustomAttribute<DebuggableAttribute>()?.IsJITTrackingEnabled ?? false; |
44 | 43 |
|
45 | 44 | sealed class SampleActionWorker<T>(Gen<T> gen, Action<T> assert, CountdownEvent cde, string? seed, long target, bool isIter) : IThreadPoolWorkItem |
46 | 45 | { |
@@ -1408,7 +1407,7 @@ public static void SampleModelBased<Actual, Model>(this Gen<(Actual, Model)> ini |
1408 | 1407 | } |
1409 | 1408 |
|
1410 | 1409 | new GenInitial<Actual, Model>(initial) |
1411 | | - .Select(Gen.OneOf(opNameActions).Array, (a, b) => new ModelBasedData<Actual, Model>(a.Actual, a.Model, a.Stream, a.Seed, b)) |
| 1410 | + .Select(Gen.OneOf(opNameActions).Array(), (a, b) => new ModelBasedData<Actual, Model>(a.Actual, a.Model, a.Stream, a.Seed, b)) |
1412 | 1411 | .Sample(d => |
1413 | 1412 | { |
1414 | 1413 | try |
@@ -1754,7 +1753,7 @@ public static void SampleParallel<T>(this Gen<T> initial, GenOperation<T>[] oper |
1754 | 1753 | Gen.Int[2, maxParallelOperations] |
1755 | 1754 | .SelectMany(np => Gen.Int[2, Math.Min(threads, np)].Select(nt => (nt, np))) |
1756 | 1755 | .SelectMany((nt, np) => Gen.Int[0, maxSequentialOperations].Select(ns => (ns, nt, np))) |
1757 | | - .SelectMany((ns, nt, np) => new GenSampleParallel<T>(initial).Select(genOps.Array[ns], genOps.Array[np]) |
| 1756 | + .SelectMany((ns, nt, np) => new GenSampleParallel<T>(initial).Select(genOps.Array()[ns], genOps.Array()[np]) |
1758 | 1757 | .Select((initial, sequential, parallel) => (initial, sequential, nt, parallel))) |
1759 | 1758 | .Select((initial, sequential, threads, parallel) => new SampleParallelData<T>(initial.Value, initial.Stream, initial.Seed, sequential, parallel, threads)) |
1760 | 1759 | .Sample(spd => |
@@ -2018,7 +2017,7 @@ public static void SampleParallel<Actual, Model>(this Gen<(Actual, Model)> initi |
2018 | 2017 | Gen.Int[2, maxParallelOperations] |
2019 | 2018 | .SelectMany(np => Gen.Int[2, Math.Min(threads, np)].Select(nt => (nt, np))) |
2020 | 2019 | .SelectMany((nt, np) => Gen.Int[0, maxSequentialOperations].Select(ns => (ns, nt, np))) |
2021 | | - .SelectMany((ns, nt, np) => new GenSampleParallel<Actual, Model>(initial).Select(genOps.Array[ns], genOps.Array[np]) |
| 2020 | + .SelectMany((ns, nt, np) => new GenSampleParallel<Actual, Model>(initial).Select(genOps.Array()[ns], genOps.Array()[np]) |
2022 | 2021 | .Select((initial, sequential, parallel) => (initial, sequential, nt, parallel))) |
2023 | 2022 | .Select((initial, sequential, threads, parallel) => new SampleParallelData<Actual, Model>(initial.Actual, initial.Model, initial.Stream, initial.Seed, sequential, parallel, threads)) |
2024 | 2023 | .Sample(spd => |
@@ -2268,7 +2267,7 @@ public void Execute() |
2268 | 2267 | { |
2269 | 2268 | if (result.Add(fasterTimer.Time(), slowerTimer.Time())) |
2270 | 2269 | { |
2271 | | - if (raiseexception && result.NotFaster && !IsDebug) |
| 2270 | + if (raiseexception && result.NotFaster) |
2272 | 2271 | result.Exception ??= new CsCheckException(result.ToString()); |
2273 | 2272 | running = false; |
2274 | 2273 | return; |
@@ -2354,7 +2353,7 @@ public void Execute() |
2354 | 2353 | { |
2355 | 2354 | if (result.Add(fasterTimer.Time(out var fasterValue), slowerTimer.Time(out var slowerValue))) |
2356 | 2355 | { |
2357 | | - if (raiseexception && result.NotFaster && !IsDebug) |
| 2356 | + if (raiseexception && result.NotFaster) |
2358 | 2357 | result.Exception ??= new CsCheckException(result.ToString()); |
2359 | 2358 | running = false; |
2360 | 2359 | return; |
@@ -2410,7 +2409,7 @@ public static void Faster<T>(Func<T> faster, Func<T> slower, Func<T, T, bool>? e |
2410 | 2409 | while (--threads > 0) |
2411 | 2410 | ThreadPool.UnsafeQueueUserWorkItem(worker, false); |
2412 | 2411 | worker.Execute(); |
2413 | | - if (raiseexception && result.NotFaster && !IsDebug) |
| 2412 | + if (raiseexception && result.NotFaster) |
2414 | 2413 | throw new CsCheckException(result.ToString()); |
2415 | 2414 | if (result.Exception is not null) throw result.Exception; |
2416 | 2415 | if (writeLine is not null) result.Output(writeLine); |
@@ -2441,7 +2440,7 @@ async Task Worker() |
2441 | 2440 | { |
2442 | 2441 | if (result.Add(await fasterTimer.Time().ConfigureAwait(false), await slowerTimer.Time().ConfigureAwait(false))) |
2443 | 2442 | { |
2444 | | - if (raiseexception && result.NotFaster && !IsDebug) |
| 2443 | + if (raiseexception && result.NotFaster) |
2445 | 2444 | result.Exception ??= new CsCheckException(result.ToString()); |
2446 | 2445 | running = false; |
2447 | 2446 | return; |
@@ -2498,7 +2497,7 @@ async Task Worker() |
2498 | 2497 | var (slowerTime, slowerValue) = await slowerTimer.Time().ConfigureAwait(false); |
2499 | 2498 | if (result.Add(fasterTime, slowerTime)) |
2500 | 2499 | { |
2501 | | - if (raiseexception && result.NotFaster && !IsDebug) |
| 2500 | + if (raiseexception && result.NotFaster) |
2502 | 2501 | result.Exception ??= new CsCheckException(result.ToString()); |
2503 | 2502 | running = false; |
2504 | 2503 | return; |
@@ -2552,7 +2551,7 @@ public void Execute() |
2552 | 2551 | t = gen.Generate(pcg, null, out _); |
2553 | 2552 | if (running && result.Add(fasterTimer.Time(t), slowerTimer.Time(t))) |
2554 | 2553 | { |
2555 | | - if (raiseexception && result.NotFaster && !IsDebug) |
| 2554 | + if (raiseexception && result.NotFaster) |
2556 | 2555 | result.Exception ??= new CsCheckException(result.ToString()); |
2557 | 2556 | running = false; |
2558 | 2557 | return; |
@@ -2757,7 +2756,7 @@ async Task Worker() |
2757 | 2756 | if (!running) return; |
2758 | 2757 | if (result.Add(await fasterTimer.Time(t).ConfigureAwait(false), await slowerTimer.Time(t).ConfigureAwait(false))) |
2759 | 2758 | { |
2760 | | - if (raiseexception && result.NotFaster && !IsDebug) |
| 2759 | + if (raiseexception && result.NotFaster) |
2761 | 2760 | result.Exception ??= new CsCheckException(result.ToString()); |
2762 | 2761 | running = false; |
2763 | 2762 | return; |
@@ -2918,7 +2917,7 @@ public void Execute() |
2918 | 2917 | t = gen.Generate(pcg, null, out _); |
2919 | 2918 | if (result.Add(fasterTimer.Time(t, out var fasterValue), slowerTimer.Time(t, out var slowerValue))) |
2920 | 2919 | { |
2921 | | - if (raiseexception && result.NotFaster && !IsDebug) |
| 2920 | + if (raiseexception && result.NotFaster) |
2922 | 2921 | result.Exception ??= new CsCheckException(result.ToString()); |
2923 | 2922 | running = false; |
2924 | 2923 | return; |
@@ -3180,7 +3179,7 @@ async Task Worker() |
3180 | 3179 | var (slowerTime, slowerValue) = await slowerTimer.Time(t).ConfigureAwait(false); |
3181 | 3180 | if (result.Add(fasterTime, slowerTime)) |
3182 | 3181 | { |
3183 | | - if (raiseexception && result.NotFaster && !IsDebug) |
| 3182 | + if (raiseexception && result.NotFaster) |
3184 | 3183 | result.Exception ??= new CsCheckException(result.ToString()); |
3185 | 3184 | running = false; |
3186 | 3185 | return; |
@@ -3555,9 +3554,7 @@ public override string ToString() |
3555 | 3554 | var result = $"{Median.Median:P2}[{Median.Q1:P2}..{Median.Q3:P2}] {times:#0.00}x[{q1Times:#0.00}x..{q3Times:#0.00}x] {faster}"; |
3556 | 3555 | if (double.IsNaN(Median.Median)) result = $"Time resolution too small try using repeat.\n{result}"; |
3557 | 3556 | else if ((Median.Median >= 0.0) != (Faster > Slower)) result = $"Inconsistent result try using repeat or increasing sigma.\n{result}"; |
3558 | | - result = $"{result}, sigma = {Math.Sqrt(SigmaSquared):#0.0} ({Faster:#,0} vs {Slower:#,0}), min = {timeString((double)FasterMin / repeat)}{timeUnit} vs {timeString((double)SlowerMin / repeat)}{timeUnit}"; |
3559 | | - if (Check.IsDebug) result += " - DEBUG MODE - DO NOT TRUST THESE RESULTS"; |
3560 | | - return result; |
| 3557 | + return $"{result}, sigma = {Math.Sqrt(SigmaSquared):#0.0} ({Faster:#,0} vs {Slower:#,0}), min = {timeString((double)FasterMin / repeat)}{timeUnit} vs {timeString((double)SlowerMin / repeat)}{timeUnit}"; |
3561 | 3558 | } |
3562 | 3559 |
|
3563 | 3560 | private static (Func<double, string>, string) TimeFormat(double maxValue) => |
|
0 commit comments