2024-02-02 21:37:18 -05:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2019-09-20 09:23:08 -04:00
|
|
|
|
2019-09-03 14:58:03 -04:00
|
|
|
import Data.Primitive (ByteArray)
|
|
|
|
import Data.Word (Word64)
|
2024-02-02 21:37:18 -05:00
|
|
|
import Gauge (bench, bgroup, whnf)
|
2019-07-05 12:35:05 -04:00
|
|
|
import Gauge.Main (defaultMain)
|
2019-09-03 14:58:03 -04:00
|
|
|
|
|
|
|
import qualified Arithmetic.Nat as Nat
|
2020-02-27 13:58:00 -05:00
|
|
|
import qualified Data.Bytes.Builder as B
|
|
|
|
import qualified Data.Bytes.Builder.Bounded as U
|
2019-07-05 12:35:05 -04:00
|
|
|
|
2019-09-20 09:23:08 -04:00
|
|
|
import qualified Cell
|
2019-07-05 12:35:05 -04:00
|
|
|
import qualified HexWord64
|
2024-02-02 21:37:18 -05:00
|
|
|
import qualified SimpleCsv
|
2019-09-22 09:20:03 -04:00
|
|
|
import qualified Word16Tree
|
2019-07-05 12:35:05 -04:00
|
|
|
|
|
|
|
main :: IO ()
|
2024-02-02 21:37:18 -05:00
|
|
|
main =
|
|
|
|
defaultMain
|
|
|
|
[ bgroup
|
|
|
|
"w64"
|
|
|
|
[ bgroup
|
|
|
|
"hex"
|
|
|
|
[ bench "library" (whnf encodeHexWord64s w64s)
|
|
|
|
, bench "loop" (whnf encodeHexWord64sLoop w64s)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
, bgroup
|
|
|
|
"unbounded"
|
|
|
|
[ bench "csv-no-escape" $
|
|
|
|
whnf
|
|
|
|
(\x -> B.run 4080 (SimpleCsv.encodeRows x))
|
|
|
|
Cell.cells
|
|
|
|
, bench "word-16-tree-small" $
|
|
|
|
whnf
|
|
|
|
(\x -> B.run 4080 (Word16Tree.encode x))
|
|
|
|
Word16Tree.exampleSmall
|
|
|
|
, bench "word-16-tree-2000" $
|
|
|
|
whnf
|
|
|
|
(\x -> B.run ((4096 * 16) - 16) (Word16Tree.encode x))
|
|
|
|
Word16Tree.example2000
|
|
|
|
, bench "word-16-tree-9000" $
|
|
|
|
whnf
|
|
|
|
(\x -> B.run ((4096 * 64) - 16) (Word16Tree.encode x))
|
|
|
|
Word16Tree.example9000
|
|
|
|
]
|
2019-07-05 12:35:05 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
w64s :: Word64s
|
2024-02-02 21:37:18 -05:00
|
|
|
w64s =
|
|
|
|
Word64s
|
|
|
|
0xde2b8a480cf77113
|
|
|
|
0x48f1668ca2a68b45
|
|
|
|
0xd262fbaa0b2f473c
|
|
|
|
0xbab20547f4919d9f
|
|
|
|
0xb7ec16121704db43
|
|
|
|
0x9c259f5bfa90e1eb
|
|
|
|
0xd451eca11d9873ad
|
|
|
|
0xbd927e8d4c879d02
|
2019-07-05 12:35:05 -04:00
|
|
|
|
2024-02-02 21:37:18 -05:00
|
|
|
data Word64s
|
|
|
|
= Word64s
|
|
|
|
!Word64
|
|
|
|
!Word64
|
|
|
|
!Word64
|
|
|
|
!Word64
|
|
|
|
!Word64
|
|
|
|
!Word64
|
|
|
|
!Word64
|
|
|
|
!Word64
|
2019-07-05 12:35:05 -04:00
|
|
|
|
|
|
|
encodeHexWord64s :: Word64s -> ByteArray
|
2024-02-02 21:37:18 -05:00
|
|
|
{-# NOINLINE encodeHexWord64s #-}
|
|
|
|
encodeHexWord64s (Word64s a b c d e f g h) =
|
|
|
|
U.run Nat.constant $
|
|
|
|
U.word64PaddedUpperHex a
|
|
|
|
`U.append` U.word64PaddedUpperHex b
|
|
|
|
`U.append` U.word64PaddedUpperHex c
|
|
|
|
`U.append` U.word64PaddedUpperHex d
|
|
|
|
`U.append` U.word64PaddedUpperHex e
|
|
|
|
`U.append` U.word64PaddedUpperHex f
|
|
|
|
`U.append` U.word64PaddedUpperHex g
|
|
|
|
`U.append` U.word64PaddedUpperHex h
|
2019-07-05 12:35:05 -04:00
|
|
|
|
|
|
|
encodeHexWord64sLoop :: Word64s -> ByteArray
|
2024-02-02 21:37:18 -05:00
|
|
|
{-# NOINLINE encodeHexWord64sLoop #-}
|
|
|
|
encodeHexWord64sLoop (Word64s a b c d e f g h) =
|
|
|
|
U.run Nat.constant $
|
|
|
|
HexWord64.word64PaddedUpperHex a
|
|
|
|
`U.append` HexWord64.word64PaddedUpperHex b
|
|
|
|
`U.append` HexWord64.word64PaddedUpperHex c
|
|
|
|
`U.append` HexWord64.word64PaddedUpperHex d
|
|
|
|
`U.append` HexWord64.word64PaddedUpperHex e
|
|
|
|
`U.append` HexWord64.word64PaddedUpperHex f
|
|
|
|
`U.append` HexWord64.word64PaddedUpperHex g
|
|
|
|
`U.append` HexWord64.word64PaddedUpperHex h
|