Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
binary
Commits
fb419199
Commit
fb419199
authored
9 years ago
by
Lennart Kolmodin
Browse files
Options
Downloads
Patches
Plain Diff
Add small Generics bench to the Put benchmark suite.
parent
b768640e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
benchmarks/Put.hs
+40
-0
40 additions, 0 deletions
benchmarks/Put.hs
binary.cabal
+6
-0
6 additions, 0 deletions
binary.cabal
with
46 additions
and
0 deletions
benchmarks/Put.hs
+
40
−
0
View file @
fb419199
{-# LANGUAGE CPP, ExistentialQuantification #-}
#
ifdef
GENERICS
{-# LANGUAGE DeriveGeneric #-}
#
endif
module
Main
(
main
)
where
...
...
@@ -9,6 +12,10 @@ import qualified Data.ByteString as S
import
qualified
Data.ByteString.Char8
as
C
import
qualified
Data.ByteString.Lazy
as
L
#
ifdef
GENERICS
import
GHC.Generics
#
endif
import
Data.Binary
import
Data.Binary.Put
import
Data.ByteString.Builder
as
BB
...
...
@@ -48,10 +55,33 @@ main = do
bench
"Word64s"
$
whnf
(
run
.
fromWord64s
)
word64s
,
bench
"Word64s builder"
$
whnf
(
L
.
length
.
toLazyByteString
.
fromWord64sBuilder
)
word64s
,
bench
"[Word64]"
$
whnf
(
run
.
put
)
word64s
#
ifdef
GENERICS
,
bgroup
"Generics"
[
bench
"Struct monoid put"
$
whnf
(
run
.
fromStructs
)
structs
,
bench
"Struct put as list"
$
whnf
(
run
.
put
)
structs
,
bench
"StructList monoid put"
$
whnf
(
run
.
fromStructLists
)
structLists
,
bench
"StructList put as list"
$
whnf
(
run
.
put
)
structLists
]
#
endif
]
where
run
=
L
.
length
.
runPut
#
ifdef
GENERICS
data
Struct
=
Struct
Word8
Word16
Word32
Word64
deriving
Generic
instance
Binary
Struct
data
StructList
=
StructList
[
Struct
]
deriving
Generic
instance
Binary
StructList
structs
::
[
Struct
]
structs
=
take
10000
$
[
Struct
a
b
0
0
|
a
<-
[
0
..
maxBound
],
b
<-
[
0
..
maxBound
]
]
structLists
::
[
StructList
]
structLists
=
replicate
1000
(
StructList
(
take
10
structs
))
#
endif
-- Input data
smallIntegers
::
[
Integer
]
...
...
@@ -135,3 +165,13 @@ fromWord64s (x:xs) = put x >> fromWord64s xs
fromWord64sBuilder
::
[
Word64
]
->
BB
.
Builder
fromWord64sBuilder
[]
=
mempty
fromWord64sBuilder
(
x
:
xs
)
=
BB
.
word64BE
x
`
mappend
`
fromWord64sBuilder
xs
#
ifdef
GENERICS
fromStructs
::
[
Struct
]
->
Put
fromStructs
[]
=
return
()
fromStructs
(
x
:
xs
)
=
put
x
>>
fromStructs
xs
fromStructLists
::
[
StructList
]
->
Put
fromStructLists
[]
=
return
()
fromStructLists
(
x
:
xs
)
=
put
x
>>
fromStructLists
xs
#
endif
This diff is collapsed.
Click to expand it.
binary.cabal
+
6
−
0
View file @
fb419199
...
...
@@ -136,6 +136,12 @@ benchmark put
-- build dependencies from using binary source rather than depending on the library
build-depends: array, containers
ghc-options: -O2 -Wall
if impl(ghc >= 7.2.1)
cpp-options: -DGENERICS
other-modules: Data.Binary.Generic
if impl(ghc <= 7.6)
-- prior to ghc-7.4 generics lived in ghc-prim
build-depends: ghc-prim
benchmark generics-bench
type: exitcode-stdio-1.0
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment