Skip to content
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

Prepare 0.3.16.1 release #36

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@byteverse/l3c
12 changes: 12 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: build
on:
pull_request:
branches:
- "*"

jobs:
call-workflow:
uses: byteverse/.github/.github/workflows/build.yaml@main
secrets: inherit
with:
release: false
12 changes: 12 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: release
on:
push:
tags:
- "*"

jobs:
call-workflow:
uses: byteverse/.github/.github/workflows/build.yaml@main
secrets: inherit
with:
release: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
dist
dist-*
cabal-dev
Expand All @@ -11,6 +12,7 @@ cabal-dev
.hsenv
.cabal-sandbox/
cabal.sandbox.config
cabal.project.local
*.prof
*.aux
*.hp
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Note: Prior to version 0.3.4.0, this library was named
`small-bytearray-builder` is now just a compatibility shim
to ease the migration process.

## 0.3.16.1 -- 2024-??-??
## 0.3.16.1 -- 2024-02-02

* Remove all CPP
* Drop support for GHC < 9.4
Expand Down Expand Up @@ -141,7 +141,7 @@ to ease the migration process.
* Add `flush`, `copy`, and `insert` for better control when
converting byte sequences to builders.
* Add `shortByteString` to improve interoperability with the
`bytestring` library.
`bytestring` library.

## 0.2.1.0 -- 2019-09-05

Expand Down
2 changes: 0 additions & 2 deletions Setup.hs

This file was deleted.

31 changes: 15 additions & 16 deletions bench/Cell.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{-# language OverloadedLists #-}
{-# language OverloadedStrings #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}

module Cell
( Cell(..)
( Cell (..)
, cells
) where

import Data.Word (Word32)
import Data.Text.Short (ShortText)
import Data.Primitive (SmallArray)
import Data.Text.Short (ShortText)
import Data.Word (Word32)

-- A cell in a CSV file
data Cell
Expand All @@ -18,15 +18,14 @@ data Cell
-- Some sample data to encode as a CSV
cells :: SmallArray (SmallArray Cell)
cells =
[ [ CellString "Randy", CellString "Gutiérrez", CellNumber 41, CellNumber 343 ]
, [ CellString "Édith", CellString "Piaf", CellNumber 63, CellNumber 453 ]
, [ CellString "Martha", CellString "Washington", CellNumber 51, CellNumber 634 ]
, [ CellString "Julius", CellString "Caesar", CellNumber 1, CellNumber 6922 ]
, [ CellString "Robert", CellString "Redford", CellNumber 24, CellNumber 617 ]
, [ CellString "Violet", CellString "Crawley", CellNumber 71, CellNumber 150 ]
, [ CellString "Lázaro", CellString "Cárdenas", CellNumber 58, CellNumber 299 ]
, [ CellString "Anastasia", CellString "San Martin", CellNumber 103, CellNumber 3214 ]
, [ CellString "Mad", CellString "Max", CellNumber 37, CellNumber 918 ]
, [ CellString "Sidonie-Gabrielle", CellString "Collette", CellNumber 25, CellNumber 904 ]
[ [CellString "Randy", CellString "Gutiérrez", CellNumber 41, CellNumber 343]
, [CellString "Édith", CellString "Piaf", CellNumber 63, CellNumber 453]
, [CellString "Martha", CellString "Washington", CellNumber 51, CellNumber 634]
, [CellString "Julius", CellString "Caesar", CellNumber 1, CellNumber 6922]
, [CellString "Robert", CellString "Redford", CellNumber 24, CellNumber 617]
, [CellString "Violet", CellString "Crawley", CellNumber 71, CellNumber 150]
, [CellString "Lázaro", CellString "Cárdenas", CellNumber 58, CellNumber 299]
, [CellString "Anastasia", CellString "San Martin", CellNumber 103, CellNumber 3214]
, [CellString "Mad", CellString "Max", CellNumber 37, CellNumber 918]
, [CellString "Sidonie-Gabrielle", CellString "Collette", CellNumber 25, CellNumber 904]
]

132 changes: 74 additions & 58 deletions bench/Main.hs
Original file line number Diff line number Diff line change
@@ -1,80 +1,96 @@
{-# language LambdaCase #-}
{-# language OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings #-}

import Data.Primitive (ByteArray)
import Data.Word (Word64)
import Gauge (bgroup,bench,whnf)
import Gauge (bench, bgroup, whnf)
import Gauge.Main (defaultMain)

import qualified Arithmetic.Nat as Nat
import qualified Data.Bytes.Builder as B
import qualified Data.Bytes.Builder.Bounded as U

import qualified Cell
import qualified SimpleCsv
import qualified HexWord64
import qualified SimpleCsv
import qualified Word16Tree

main :: IO ()
main = defaultMain
[ bgroup "w64"
[ bgroup "hex"
[ bench "library" (whnf encodeHexWord64s w64s)
, bench "loop" (whnf encodeHexWord64sLoop w64s)
]
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
]
]
, 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
]
]

w64s :: Word64s
w64s = Word64s
0xde2b8a480cf77113
0x48f1668ca2a68b45
0xd262fbaa0b2f473c
0xbab20547f4919d9f
0xb7ec16121704db43
0x9c259f5bfa90e1eb
0xd451eca11d9873ad
0xbd927e8d4c879d02
w64s =
Word64s
0xde2b8a480cf77113
0x48f1668ca2a68b45
0xd262fbaa0b2f473c
0xbab20547f4919d9f
0xb7ec16121704db43
0x9c259f5bfa90e1eb
0xd451eca11d9873ad
0xbd927e8d4c879d02

data Word64s = Word64s
!Word64 !Word64 !Word64 !Word64
!Word64 !Word64 !Word64 !Word64
data Word64s
= Word64s
!Word64
!Word64
!Word64
!Word64
!Word64
!Word64
!Word64
!Word64

encodeHexWord64s :: Word64s -> ByteArray
{-# 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
{-# 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

encodeHexWord64sLoop :: Word64s -> ByteArray
{-# 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

{-# 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
22 changes: 12 additions & 10 deletions bench/SimpleCsv.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# language LambdaCase #-}
{-# LANGUAGE LambdaCase #-}

-- A variant of CSV encoding that does not perform
-- any escaping or quoting. This is in its own module
Expand All @@ -8,22 +8,24 @@ module SimpleCsv
( encodeRows
) where

import Cell (Cell(..))
import Cell (Cell (..))
import Data.Primitive (SmallArray)

import qualified Data.Foldable as F
import qualified Data.Bytes.Builder as B
import qualified Data.Foldable as F

encodeRows :: SmallArray (SmallArray Cell) -> B.Builder
encodeRows = F.foldr
(\r x -> encodeSimpleCsvRow r (B.ascii '\n' <> x))
mempty
encodeRows =
F.foldr
(\r x -> encodeSimpleCsvRow r (B.ascii '\n' <> x))
mempty

encodeSimpleCsvRow :: SmallArray Cell -> B.Builder -> B.Builder
encodeSimpleCsvRow cs b = F.foldr
(\c x -> encodeSimpleCsvCell c <> B.ascii ',' <> x)
b
cs
encodeSimpleCsvRow cs b =
F.foldr
(\c x -> encodeSimpleCsvCell c <> B.ascii ',' <> x)
b
cs

encodeSimpleCsvCell :: Cell -> B.Builder
encodeSimpleCsvCell = \case
Expand Down
Loading
Loading