From d09dd1f6975771946f76a5556050cfc6eddd3eda Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 16 Dec 2022 16:35:49 +0100 Subject: [PATCH] Allow for dry-running benchmark test (#3989) When integrated with CI, will guard against any compilation failures. Can be enabled via env var `ENSO_BENCHMARK_TEST_DRY_RUN="True"`: ``` ENSO_BENCHMARK_TEST_DRY_RUN="True" built-distribution/enso-engine-0.0.0-dev-linux-amd64/enso-0.0.0-dev/bin/enso --run test/Benchmarks ``` # Important Notes /cc @mwu-tow this could be run only on linux PRs in CI --- .../Standard/Test/0.0.0-dev/src/Bench.enso | 20 ++++++++++++------- .../src/Statistics/Count_Min_Max.enso | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso b/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso index 5f5794fbd7b..ba8da26143f 100644 --- a/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso +++ b/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso @@ -20,23 +20,29 @@ type Bench example_measure = Bench.measure Examples.get_boolean "foo" iter_size=2 num_iters=1 measure : Any -> Text -> Integer -> Integer -> Nothing - measure = ~act -> label -> iter_size -> num_iters -> + measure = ~act -> label -> iter_size -> num_iters -> + dry_run = Environment.get_or_else "ENSO_BENCHMARK_TEST_DRY_RUN" "False" == "True" result = Ref.new 0.0 single_call = _ -> x1 = System.nano_time Runtime.no_inline act x2 = System.nano_time x2 - x1 - iteration = it_num -> + iteration = it_size -> it_num -> act_it_num = num_iters - it_num - res = times iter_size single_call + res = times it_size single_call avg = avg_list res fmt = (avg / 1000000).format "%.2f" result.put (result.get + avg) - IO.println (label + "/iteration:" + act_it_num.to_text + ": " + fmt + "ms") - times num_iters iteration - fmt_avg = (result.get / (1000000*num_iters)).format "%.2f" - IO.println (label + " average: " + fmt_avg + "ms") + case dry_run of + False -> + IO.println (label + "/iteration:" + act_it_num.to_text + ": " + fmt + "ms") + True -> + IO.println (label + "/dry-run: " + fmt) + if dry_run then times 1 (iteration 1) else + times num_iters (iteration iter_size) + fmt_avg = (result.get / (1000000*num_iters)).format "%.2f" + IO.println (label + " average: " + fmt_avg + "ms") ## PRIVATE diff --git a/test/Benchmarks/src/Statistics/Count_Min_Max.enso b/test/Benchmarks/src/Statistics/Count_Min_Max.enso index d43d1eaa2f8..3a6d59cebda 100644 --- a/test/Benchmarks/src/Statistics/Count_Min_Max.enso +++ b/test/Benchmarks/src/Statistics/Count_Min_Max.enso @@ -1,5 +1,6 @@ from Standard.Base import IO, Integer, Vector from Standard.Base.Data.Statistics import all +import Standard.Base.Data.Range from Standard.Test import Bench, Faker