Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some additions to Data.Tree #1109

Merged
merged 6 commits into from
Feb 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PostOrder benchmarks
  • Loading branch information
meooow25 committed Feb 19, 2025
commit 9c7d45b2e068ef41a31935d838015a79cb193155
31 changes: 31 additions & 0 deletions containers-tests/benchmarks/Tree.hs
Original file line number Diff line number Diff line change
@@ -45,6 +45,34 @@ main = do
, bgroup "foldlMap1" $ forTs ts $ whnf (Foldable1.foldlMap1 id (+))
]
#endif
, bgroup "PostOrder"
[ bgroup "Foldable"
[ bgroup "folds"
[ bgroup label $
foldBenchmarks foldr foldl F.foldr' F.foldl' foldMap (T.PostOrder t)
| Tree label t <- ts
]
, bgroup "foldr1" $ forPostOrders tsBool $ whnf (foldr1 (&&))
, bgroup "foldl1" $ forPostOrders ts $ whnf (foldl1 (+))
, bgroup "toList" $ forPostOrders ts $ nf F.toList
, bgroup "elem" $ forPostOrders ts $ whnf (elem 0)
, bgroup "maximum" $ forPostOrders ts $ whnf maximum
, bgroup "sum" $ forPostOrders ts $ whnf sum
]
#if MIN_VERSION_base(4,18,0)
, bgroup "Foldable1"
[ bgroup "fold1" $ forPostOrders tsBool $ whnf Foldable1.fold1 . (coerce :: T.PostOrder Bool -> T.PostOrder All)
, bgroup "foldMap1" $ forPostOrders tsBool $ whnf (Foldable1.foldMap1 All)
, bgroup "foldMap1'" $ forPostOrders ts $ whnf (Foldable1.foldMap1' Sum)
, bgroup "toNonEmpty" $ forPostOrders ts $ nf Foldable1.toNonEmpty
, bgroup "maximum" $ forPostOrders ts $ whnf Foldable1.maximum
, bgroup "foldrMap1_1" $ forPostOrders tsBool $ whnf (Foldable1.foldrMap1 id (&&))
, bgroup "foldrMap1_2" $ forPostOrders ts $ whnf (length . Foldable1.foldrMap1 (:[]) (:))
, bgroup "foldlMap1'" $ forPostOrders ts $ whnf (Foldable1.foldlMap1' id (+))
, bgroup "foldlMap1" $ forPostOrders ts $ whnf (Foldable1.foldlMap1 id (+))
]
#endif
]
]
where
ts = [binaryTree, lineTree] <*> [1000, 1000000]
@@ -53,6 +81,9 @@ main = do
forTs :: [Tree a] -> (T.Tree a -> Benchmarkable) -> [Benchmark]
forTs ts f = [bench label (f t) | Tree label t <- ts]

forPostOrders :: [Tree a] -> (T.PostOrder a -> Benchmarkable) -> [Benchmark]
forPostOrders ts f = forTs ts (f . T.PostOrder)

data Tree a = Tree
{ getLabel :: String
, getT :: T.Tree a
Loading