-
Notifications
You must be signed in to change notification settings - Fork 187
Implement fromSetA for IntMap and Map #1163
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
Changes from all commits
b04c607
69b5be2
29cacf7
6b918a4
0052755
2d3f137
570b815
a68385d
e6b84ff
d0c76d4
5ff0726
0959161
eb33e4a
69d86da
e1d178b
a10287b
df8252d
33a10c3
7cb4508
fc3bb52
efe1735
d9623e4
e3f8d2a
c8f192b
0295d5c
8ba0cff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #! /bin/bash | ||
|
|
||
| # convenience script to run all benchmarks for the master branch and for the | ||
| # starting branch, and compare the before and after in the output file | ||
| # bench-$CURR_BRANCH_NAME.out, in `benchmark_tmp/` | ||
|
|
||
| exitWith () { | ||
| echo "$1" | ||
| exit $(($2)) | ||
| } | ||
|
|
||
| if [ -n "$(git status --porcelain)" ]; then | ||
| echo "there are changes, exiting benchmark script"; | ||
| exit 1 | ||
| fi | ||
|
|
||
| CURR=`git rev-parse --abbrev-ref HEAD` | ||
|
|
||
| if [ "$CURR" == "master" ] | ||
| then | ||
| exitWith "current branch is master, ending benchmarking" -1 | ||
| fi | ||
|
|
||
| BENCHMARKS=( | ||
| intmap-benchmarks | ||
| intset-benchmarks | ||
| map-benchmarks | ||
| tree-benchmarks | ||
| sequence-benchmarks | ||
| set-benchmarks | ||
| graph-benchmarks | ||
| set-operations-intmap | ||
| set-operations-intset | ||
| set-operations-map | ||
| set-operations-set | ||
| lookupge-intmap | ||
| lookupge-map | ||
| ) | ||
|
|
||
| BENCHMARK_TMP="benchmark_tmp" | ||
|
|
||
| mkdir -p $BENCHMARK_TMP | ||
|
|
||
| git checkout master | ||
|
|
||
| cabal build all || exitWith "master build errored" 2 | ||
|
|
||
| MASTER_BENCH_LOG="$BENCHMARK_TMP/bench-master.log" | ||
| echo -n > $MASTER_BENCH_LOG | ||
|
|
||
| for BENCHMARK in "${BENCHMARKS[@]}" | ||
| do | ||
| echo "running $BENCHMARK on master" | ||
| (cabal bench $BENCHMARK --benchmark-options="--csv $BENCHMARK.csv" >> $MASTER_BENCH_LOG 2>&1) || | ||
| exitWith "benchmark $BENCHMARK failed to run on master, exiting" 3 | ||
| done | ||
|
|
||
| git checkout $CURR | ||
|
|
||
| cabal build all || exitWith "$CURR build errored" 4 | ||
|
|
||
| CURR_BENCH_LOG="$BENCHMARK_TMP/bench-$CURR.log" | ||
| echo -n > $CURR_BENCH_LOG | ||
|
|
||
| for BENCHMARK in "${BENCHMARKS[@]}" | ||
| do | ||
| echo "running $BENCHMARK on $CURR" | ||
| (cabal bench $BENCHMARK --benchmark-options="--csv $BENCHMARK-$CURR.csv --baseline $BENCHMARK.csv" >> $CURR_BENCH_LOG 2>&1) || | ||
| exitWith "benchmark $BENCHMARK failed to run on $CURR, exiting" 5 | ||
| done | ||
|
|
||
| mv containers-tests/*.csv $BENCHMARK_TMP/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,12 @@ instance Arbitrary a => Arbitrary (Bot a) where | |
| , (4, Bot <$> arbitrary) | ||
| ] | ||
|
|
||
| instance CoArbitrary a => CoArbitrary (Bot a) where | ||
| coarbitrary (Bot x) = coarbitrary x | ||
|
|
||
| instance Function a => Function (Bot a) where | ||
| function = functionMap (\(Bot x) -> x) Bot | ||
|
|
||
|
Comment on lines
+30
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These shouldn't be necessary.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why you say that. It avoids having to unwrap the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to remove this theoretically. Note that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do you have any example of where we would want this instance? |
||
| {-------------------------------------------------------------------- | ||
| Lazy functions | ||
| --------------------------------------------------------------------} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,15 +8,17 @@ import Data.Bifunctor (bimap) | |
| import Data.Coerce (coerce) | ||
| import Data.Either (partitionEithers) | ||
| import qualified Data.Foldable as F | ||
| import Data.Functor.Identity (Identity(..)) | ||
| import Data.Function (on) | ||
| import Data.Functor.Compose | ||
| import Data.Functor.Identity (Identity(..)) | ||
| import qualified Data.List as List | ||
| import qualified Data.List.NonEmpty as NE | ||
| import Data.Maybe (catMaybes, mapMaybe) | ||
| import Data.Ord (comparing) | ||
| import Test.ChasingBottoms.IsBottom | ||
| import Test.Tasty (TestTree, defaultMain, testGroup) | ||
| import Test.Tasty.QuickCheck (testProperty) | ||
| import Data.Tuple.Solo (Solo (MkSolo), getSolo) | ||
| import Test.QuickCheck | ||
| import Test.QuickCheck.Poly (A, B, C) | ||
| import Test.QuickCheck.Function (apply) | ||
|
|
@@ -68,12 +70,35 @@ prop_strictFromSet :: Func Key (Bot A) -> IntSet -> Property | |
| prop_strictFromSet fun set = | ||
| isBottom (M.fromSet f set) === any (isBottom . f) (IntSet.toList set) | ||
| where | ||
| f = coerce (applyFunc fun) :: Key -> A | ||
| f = applyFunc fun | ||
|
|
||
| prop_strictFromSetA :: Func Key (Bot A) -> IntSet -> Property | ||
| prop_strictFromSetA fun set = | ||
| isBottom (getSolo (M.fromSetA (MkSolo . f) set)) === any (isBottom . f) (IntSet.toList set) | ||
| where | ||
| f = applyFunc fun | ||
|
Comment on lines
+75
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a weird way to do this. What we want in the test here is a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not about what might seem clearer in this particular case, it's a simple mechanical translation from the type of the function being tested which can be applied to all tests here. |
||
|
|
||
| prop_lazyFromSet :: Func Key (Bot A) -> IntSet -> Property | ||
| prop_lazyFromSet fun set = isNotBottomProp (L.fromSet f set) | ||
| where | ||
| f = coerce (applyFunc fun) :: Key -> A | ||
| f = applyFunc fun | ||
|
|
||
| prop_lazyFromSetA :: Func Key (Bot A) -> IntSet -> Property | ||
| prop_lazyFromSetA fun set = isNotBottomProp (getSolo (L.fromSetA f set)) | ||
| where | ||
| f = MkSolo . applyFunc fun | ||
|
|
||
| prop_fromSetA_equiv_strictness :: Func Int (Bot A) -> IntSet -> Property | ||
| prop_fromSetA_equiv_strictness fun set = | ||
| -- strict fromSetA is the same as lazy and then forcing | ||
| bottomOn (M.fromSetA f set) (fmap forceValues (L.fromSetA f set)) .&&. | ||
| -- strict fromSetA is the same as lazy fromSetA composed with strictly applied | ||
| -- wrapper | ||
| bottomOn (M.fromSetA f set) (fmap getSolo . getCompose $ L.fromSetA (Compose . fmap (MkSolo $!) . f) set) | ||
| where | ||
| forceValues xs = foldr (\ !_ r -> r) () xs `seq` xs | ||
| bottomOn = (===) `on` isBottom . getSolo | ||
| f = MkSolo . applyFunc fun | ||
|
|
||
| prop_strictFromList :: [(Key, Bot A)] -> Property | ||
| prop_strictFromList kvs = | ||
|
|
@@ -1015,6 +1040,8 @@ tests = | |
| , testGroup "Construction" | ||
| [ testPropStrictLazy "singleton" prop_strictSingleton prop_lazySingleton | ||
| , testPropStrictLazy "fromSet" prop_strictFromSet prop_lazyFromSet | ||
| , testPropStrictLazy "fromSetA" prop_strictFromSetA prop_lazyFromSetA | ||
| , testProperty "fromSetA equivalences" prop_fromSetA_equiv_strictness | ||
| , testPropStrictLazy "fromList" prop_strictFromList prop_lazyFromList | ||
| , testPropStrictLazy "fromListWith" prop_strictFromListWith prop_lazyFromListWith | ||
| , testPropStrictLazy "fromListWithKey" prop_strictFromListWithKey prop_lazyFromListWithKey | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.