Skip to content

Commit d8d5a9a

Browse files
committed
add Snocing benchmarks
With datatypes that do efficient snocing - it is often easier to reason about & build algorithms on, as data structure becomes FIFO. As for example accumulator would add to the tail & then traversing the data structure alalizing elements from old to new, which is easy to align with laziness. DList & Acc also shine in snocing, that is also a main point to add snocing.
1 parent f41659b commit d8d5a9a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Time.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import System.Directory
2424
import System.Random
2525

2626
data Conser = forall f. NFData (f Int) => Conser String (Int -> IO (f Int)) (Int -> f Int -> f Int)
27+
data Snocer = forall f. NFData (f Int) => Snocer String (Int -> IO (f Int)) (f Int -> Int -> f Int)
2728
data Append = forall f. NFData (f Int) => Append String (Int -> IO (f Int)) (f Int -> f Int -> f Int) (f Int -> f Int)
2829
data Replicator = forall f. NFData (f Int) => Replicator String (Int -> Int -> f Int)
2930
data Indexing = forall f. NFData (f Int) => Indexing String (IO (f Int)) (f Int -> Int -> Int)
@@ -53,6 +54,17 @@ main = do
5354
, Conser "Data.RRBVector" sampleRRB (RRB.<|)
5455
, Conser "Data.Acc" sampleAcc Acc.cons
5556
])
57+
, bgroup
58+
"Snocing"
59+
(snocs
60+
[ Snocer "Data.DList" sampleDList D.snoc
61+
, Snocer "Data.Vector" sampleVector V.snoc
62+
, Snocer "Data.Vector.Unboxed" sampleUVVector UV.snoc
63+
, Snocer "Data.Vector.Storable" sampleSVVector SV.snoc
64+
, Snocer "Data.Sequence" sampleSeq (S.|>)
65+
, Snocer "Data.RRBVector" sampleRRB (RRB.|>)
66+
, Snocer "Data.Acc" sampleAcc (flip Acc.snoc)
67+
])
5668
, bgroup
5769
"Indexing"
5870
(let size = 10005
@@ -182,6 +194,13 @@ main = do
182194
| i <- [10, 100, 1000, 10000]
183195
, Conser title sample func <- funcs
184196
]
197+
snocs funcs =
198+
[ env
199+
(sample i)
200+
(\p -> bench (title ++ ":" ++ show i) (whnf (\e -> func p e) 1))
201+
| i <- [10, 100, 1000, 10000]
202+
, Snocer title sample func <- funcs
203+
]
185204
replicators funcs =
186205
[ bench (title ++ ":" ++ show i) $ nf (\(x, y) -> func x y) (i, 1234)
187206
| i <- [10, 100, 1000, 10000]

0 commit comments

Comments
 (0)