-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
74eb50c
commit dca4e0b
Showing
4 changed files
with
59 additions
and
0 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 +1,2 @@ | ||
dist-newstyle/ | ||
Session.vim |
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,16 @@ | ||
module Main where | ||
|
||
import Data.Text qualified as Text | ||
import Data.Text.Lazy qualified as Text.Lazy | ||
import Data.Text.Lazy.Builder qualified as Text.Lazy.Builder | ||
import Data.Text.Lazy.Builder.Int qualified as Text.Lazy.Builder | ||
import ParkBench | ||
import Proem.Text qualified | ||
|
||
main :: IO () | ||
main = do | ||
benchmark | ||
[ function "pack . show" (Text.pack . show) (-1000), | ||
function "toStrict . toLazyText . decimal" (Text.Lazy.toStrict . Text.Lazy.Builder.toLazyText . Text.Lazy.Builder.decimal) (-1000), | ||
function "Proem.Text.fromInt" Proem.Text.fromInt (-1000) | ||
] |
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
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,27 @@ | ||
module Proem.Text | ||
( fromInt, | ||
) | ||
where | ||
|
||
import Data.Text (Text) | ||
import qualified Data.Text as Text | ||
import qualified Data.Text.Lazy as Text.Lazy | ||
import qualified Data.Text.Lazy.Builder as Text.Lazy.Builder | ||
import qualified Data.Text.Lazy.Builder.Int as Text.Lazy.Builder | ||
import Prelude | ||
|
||
-- | Construct a text from an int. | ||
fromInt :: Int -> Text | ||
fromInt n = | ||
-- Benchmarking seems to indicate going through a proper builder becomes faster at 5 characters | ||
if n >= 0 | ||
then if n < 9999 then stringy n else buildery n | ||
else if n >= -999 then stringy n else buildery n | ||
where | ||
stringy :: Int -> Text | ||
stringy = | ||
Text.pack . show | ||
|
||
buildery :: Int -> Text | ||
buildery = | ||
Text.Lazy.toStrict . Text.Lazy.Builder.toLazyText . Text.Lazy.Builder.decimal |