From a806d95dccb678c65bc650119da638a0f886fd8a Mon Sep 17 00:00:00 2001 From: min-nguyen Date: Sat, 23 Sep 2023 16:59:16 +0100 Subject: [PATCH] Run benchmarks multiple times --- test/Benchmark.purs | 12 +++++++----- test/Main.purs | 8 ++++---- test/Many.purs | 20 +++++++++++--------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/test/Benchmark.purs b/test/Benchmark.purs index f77643fca..40a8728c3 100644 --- a/test/Benchmark.purs +++ b/test/Benchmark.purs @@ -19,18 +19,20 @@ import Util (type (×), (×)) main :: Effect Unit main = launchAff_ do - let arr = concat [ bench_misc, bench_desugaring, bench_bwd, bench_graphics ] + let + iter = 10 + arr = concat ([ bench_misc, bench_desugaring, bench_bwd, bench_graphics ] <#> (#) iter) outs <- sequence $ map (\(str × row) -> lift2 Tuple (pure str) row) arr logShow $ BenchAcc outs -bench_desugaring :: Array (String × Aff BenchRow) +bench_desugaring :: Int -> Array (String × Aff BenchRow) bench_desugaring = many desugar_cases -bench_misc :: Array (String × Aff BenchRow) +bench_misc :: Int -> Array (String × Aff BenchRow) bench_misc = many misc_cases -bench_bwd :: Array (String × Aff BenchRow) +bench_bwd :: Int -> Array (String × Aff BenchRow) bench_bwd = bwdMany bwd_cases -bench_graphics :: Array (String × Aff BenchRow) +bench_graphics :: Int -> Array (String × Aff BenchRow) bench_graphics = withDatasetMany graphics_cases diff --git a/test/Main.purs b/test/Main.purs index 6c01dd5db..bc30a4a5b 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -35,16 +35,16 @@ tests = concat -- test_scratchpad = [] test_desugaring :: Array (String × Aff Unit) -test_desugaring = second void <$> many desugar_cases +test_desugaring = second void <$> many desugar_cases 1 test_misc :: Array (String × Aff Unit) -test_misc = second void <$> many misc_cases +test_misc = second void <$> many misc_cases 1 test_bwd :: Array (String × Aff Unit) -test_bwd = second void <$> bwdMany bwd_cases +test_bwd = second void <$> bwdMany bwd_cases 1 test_graphics :: Array (String × Aff Unit) -test_graphics = second void <$> withDatasetMany graphics_cases +test_graphics = second void <$> withDatasetMany graphics_cases 1 test_linking :: Array (String × Aff Unit) test_linking = linkMany linking_cases diff --git a/test/Many.purs b/test/Many.purs index 3ece0aa68..f01fdcc7f 100644 --- a/test/Many.purs +++ b/test/Many.purs @@ -12,37 +12,39 @@ import Test.Util (TestBwdSpec, TestLinkSpec, TestSpec, TestWithDatasetSpec, aver import Util (type (×), (×), successful) import Val ((<+>)) -many :: Array TestSpec -> Array (String × Aff BenchRow) -many fxs = zip names affs +many :: Array TestSpec -> Int -> Array (String × Aff BenchRow) +many fxs iter = zip names affs where affs = fxs <#> \{ file, fwd_expect } -> do default <- openDefaultImports expr <- open (File file) - rows <- replicateM 1 $ testWithSetup file expr default { δv: identity, fwd_expect, bwd_expect: mempty } + rows <- replicateM iter $ + testWithSetup file expr default { δv: identity, fwd_expect, bwd_expect: mempty } pure $ averageRows rows names = map _.file fxs -bwdMany :: Array TestBwdSpec -> Array (String × Aff BenchRow) -bwdMany fxs = zip names affs +bwdMany :: Array TestBwdSpec -> Int -> Array (String × Aff BenchRow) +bwdMany fxs iter = zip names affs where folder = File "slicing/" affs = fxs <#> \{ file, file_expect, δv, fwd_expect } -> do default <- openDefaultImports bwd_expect <- loadFile (Folder "fluid/example") (folder <> File file_expect) expr <- open (folder <> File file) - rows <- replicateM 1 $ testWithSetup file expr default { δv, fwd_expect, bwd_expect } + rows <- replicateM iter $ + testWithSetup file expr default { δv, fwd_expect, bwd_expect } pure $ averageRows rows names = map _.file fxs -withDatasetMany :: Array TestWithDatasetSpec -> Array (String × Aff BenchRow) -withDatasetMany fxs = zip names affs +withDatasetMany :: Array TestWithDatasetSpec -> Int -> Array (String × Aff BenchRow) +withDatasetMany fxs iter = zip names affs where affs = fxs <#> \{ dataset, file } -> do default <- openDefaultImports { g, n, γα } × xv <- openDatasetAs (File dataset) "data" default let loadedData = { g, n, γα: γα <+> xv } expr <- open (File file) - rows <- replicateM 1 $ + rows <- replicateM iter $ testWithSetup file expr loadedData { δv: identity, fwd_expect: mempty, bwd_expect: mempty } pure $ averageRows rows names = fxs <#> _.file