-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
dist | ||
.cabal-sandbox/ | ||
cabal.sandbox.config | ||
.stack-work/ | ||
|
||
*.o | ||
*.hi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
import Criterion.Main | ||
import Data.Aeson | ||
import Data.Foldable (toList) | ||
|
||
import qualified Data.Sequence as S | ||
import qualified Data.Vector as V | ||
import qualified Data.Vector.Unboxed as U | ||
|
||
------------------------------------------------------------------------------- | ||
-- List | ||
------------------------------------------------------------------------------- | ||
|
||
newtype L f = L { getL :: f Int } | ||
|
||
instance Foldable f => ToJSON (L f) where | ||
toJSON = error "do not use this" | ||
toEncoding = toEncoding . toList . getL | ||
|
||
------------------------------------------------------------------------------- | ||
-- Foldable | ||
------------------------------------------------------------------------------- | ||
|
||
newtype F f = F { getF :: f Int } | ||
|
||
instance Foldable f => ToJSON (F f) where | ||
toJSON = error "do not use this" | ||
toEncoding = foldable . getF | ||
|
||
------------------------------------------------------------------------------- | ||
-- Values | ||
------------------------------------------------------------------------------- | ||
|
||
valueList :: [Int] | ||
valueList = [1..1000] | ||
|
||
valueSeq :: S.Seq Int | ||
valueSeq = S.fromList valueList | ||
|
||
valueVector :: V.Vector Int | ||
valueVector = V.fromList valueList | ||
|
||
valueUVector :: U.Vector Int | ||
valueUVector = U.fromList valueList | ||
|
||
------------------------------------------------------------------------------- | ||
-- Main | ||
------------------------------------------------------------------------------- | ||
|
||
benchEncode | ||
:: ToJSON a | ||
=> String | ||
-> a | ||
-> Benchmark | ||
benchEncode name val | ||
= bench name $ nf encode val | ||
|
||
main :: IO () | ||
main = defaultMain | ||
[ bgroup "encode" | ||
[ bgroup "List" | ||
[ benchEncode "-" valueList | ||
, benchEncode "L" $ L valueList | ||
, benchEncode "F" $ F valueList | ||
] | ||
, bgroup "Seq" | ||
[ benchEncode "-" valueSeq | ||
, benchEncode "L" $ L valueSeq | ||
, benchEncode "F" $ F valueSeq | ||
] | ||
, bgroup "Vector" | ||
[ benchEncode "-" valueVector | ||
, benchEncode "L" $ L valueVector | ||
, benchEncode "F" $ F valueVector | ||
] | ||
, bgroup "Vector.Unboxed" | ||
[ benchEncode "-" valueUVector | ||
] | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters