Builder for Data.Fixed?
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with the Data.Fixed type and the fixedDec example in the issue, then inspect the existing bytestring Builder APIs for numeric encoders. Compare the current logBase-based zero calculation with possible integer-based approaches and establish benchmarks for repeated Fixed values. Done means an efficient Fixed builder is defined and its performance is demonstrated against the supplied implementation.
Written by the indexing model from the issue text.
Description
I wonder if there is a fast ByteString Builder for numbers from Data.Fixed?
I've written one myself, but don't think it's quite as fast as it could be:
-- | Encode a 'Fixed' resolution number using ASCII digits.
fixedDec :: HasResolution a => Fixed a -> BB.Builder
fixedDec fa@(MkFixed a) | a < 0 = P.primFixed P.char8 '-' <> fixedDec (asTypeOf (MkFixed (negate a)) fa)
fixedDec fa@(MkFixed a) = integerDec i <> P.primFixed P.char8 '.' <> stimesMonoid zeros (P.primFixed P.char8 '0') <> integerDec d
where
(i, d) = a `quotRem` resolution fa
zeros :: Integer = if d == 0 then 0 else ceiling (logBase 10 (fromIntegral (resolution fa) / fromIntegral d / 10) :: Double)
Calculating logBase 10 gets expensive, so it doesn't seem to perform well with lots of Fixed numbers.
Ideally if there was an efficient builder of fixed, it could be included in bytestring. Anyone have ideas of how to make it more efficient?
- Dominant language
- Haskell
- Stars
- 302
- Forks
- 146
- Avg merge
- 7d 21h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from haskell/bytestring
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
haskell/bytestring#730 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
haskell/bytestring#723 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
haskell/bytestring#697 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
haskell/bytestring#684 · 3 comments ·
-
Fixed Point RoundingOpen
Difficulty 5/5 Over a week Newbie friendliness 25/100
haskell/bytestring#679 · 2 comments ·
All issues in haskell/bytestring
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
seal-harness/seal-harness#399 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
fmidue/codeworld-tasks#124 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
reflex-frp/reflex#563 ·
-
The codecov job never gets a runner on macos-26 and is cancelledPossibly taken @yegor256 claimed this 1 day ago. Openbug
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
objectionary/phino#2524 · 1 comment ·
Maintainers usually reply within 1 day