Skip to content

Commit

Permalink
Run benchmarks multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
min-nguyen committed Sep 23, 2023
1 parent 6d1458d commit a806d95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
12 changes: 7 additions & 5 deletions test/Benchmark.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 11 additions & 9 deletions test/Many.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a806d95

Please sign in to comment.