urbit-hob

Haskell utilities for phonetic base wrangling.
Log | Files | Refs | README | LICENSE

commit ac4c1400b8f5772e9b52f4b19243dfb5426568f8
parent f94ecc0a8d57587f13d7d69f5c256e13fa5f6fe9
Author: Jared Tobin <jared@jtobin.io>
Date:   Wed, 18 Sep 2019 19:47:50 -0230

bench: add benchmark suite

Adds a suite for benchmarking the core exported functions using
criterion.  Also adds a Generic instance for Patp, which is used to
implement a NFData instance in the bench suite.

Diffstat:
Abench/Ob.hs | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlib/Urbit/Ob/Co.hs | 4+++-
Astack.yaml.lock | 12++++++++++++
Murbit-hob.cabal | 17+++++++++++++++--
4 files changed, 119 insertions(+), 3 deletions(-)

diff --git a/bench/Ob.hs b/bench/Ob.hs @@ -0,0 +1,89 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main where + +import Control.DeepSeq +import Criterion.Main +import qualified Urbit.Ob as Ob + +instance NFData Ob.Patp + +patpGroup :: Benchmark +patpGroup = bgroup "patp" [ + bench "~zod" $ + nf Ob.patp 0x0000 + + , bench "~marzod" $ + nf Ob.patp 0x0100 + + , bench "~dapnep-ronmyl" $ + nf Ob.patp 0x00010000 + + , bench "~fipfes-fipfes-dostec-risfen" $ + nf Ob.patp 0xFFFFFFFFFFFFFFFF + + , bench "~fipfes-fipfes-fipfes-fipfes--fipfes-fipfes-fipfes-fipfes" $ + nf Ob.patp 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + ] + +fromPatpGroup :: Benchmark +fromPatpGroup = bgroup "fromPatp" [ + bench "~zod" $ + whnf Ob.fromPatp (Ob.patp 0x0000) + + , bench "~marzod" $ + whnf Ob.fromPatp (Ob.patp 0x0100) + + , bench "~dapnep-ronmyl" $ + whnf Ob.fromPatp (Ob.patp 0x00010000) + + , bench "~fipfes-fipfes-dostec-risfen" $ + whnf Ob.fromPatp (Ob.patp 0xFFFFFFFFFFFFFFFF) + + , bench "~fipfes-fipfes-fipfes-fipfes--fipfes-fipfes-fipfes-fipfes" $ + whnf Ob.fromPatp (Ob.patp 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) + ] + +renderGroup :: Benchmark +renderGroup = bgroup "render" [ + bench "~zod" $ + nf Ob.render (Ob.patp 0x0000) + + , bench "~marzod" $ + nf Ob.render (Ob.patp 0x0100) + + , bench "~dapnep-ronmyl" $ + nf Ob.render (Ob.patp 0x00010000) + + , bench "~fipfes-fipfes-dostec-risfen" $ + nf Ob.render (Ob.patp 0xFFFFFFFFFFFFFFFF) + + , bench "~fipfes-fipfes-fipfes-fipfes--fipfes-fipfes-fipfes-fipfes" $ + nf Ob.render (Ob.patp 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) + ] + +parseGroup :: Benchmark +parseGroup = bgroup "parse" [ + bench "~zod" $ + nf Ob.parse "~zod" + + , bench "~marzod" $ + nf Ob.parse "~marzod" + + , bench "~dapnep-ronmyl" $ + nf Ob.parse "~dapnep-ronmyl" + + , bench "~fipfes-fipfes-dostec-risfen" $ + nf Ob.parse "~fipfes-fipfes-dostec-risfen" + + , bench "~fipfes-fipfes-fipfes-fipfes--fipfes-fipfes-fipfes-fipfes" $ + nf Ob.parse "~fipfes-fipfes-fipfes-fipfes--fipfes-fipfes-fipfes-fipfes" + ] + +main :: IO () +main = defaultMain [ + patpGroup + , fromPatpGroup + , renderGroup + , parseGroup + ] diff --git a/lib/Urbit/Ob/Co.hs b/lib/Urbit/Ob/Co.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} -- | @@ -30,6 +31,7 @@ import qualified Data.Serialize.Extended as C import qualified Data.Text as T import qualified Data.Vector as V import Data.Word (Word8) +import GHC.Generics (Generic) import Numeric.Natural (Natural) import Prelude hiding (log) import qualified Urbit.Ob.Ob as Ob (fein, fynd) @@ -45,7 +47,7 @@ import qualified Urbit.Ob.Ob as Ob (fein, fynd) -- (It's also used for naming comets, i.e. self-signed 128-bit Urbit ships.) -- newtype Patp = Patp BS.ByteString - deriving Eq + deriving (Eq, Generic) instance Show Patp where show = T.unpack . render diff --git a/stack.yaml.lock b/stack.yaml.lock @@ -0,0 +1,12 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + size: 498155 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/19.yaml + sha256: b9367a80d4393d02e58a46b8a9fdfbd7bc19f59c0c2bbf90034ba15cf52cf213 + original: lts-13.19 diff --git a/urbit-hob.cabal b/urbit-hob.cabal @@ -50,9 +50,9 @@ library hs-source-dirs: lib if flag(release) - ghc-options: -Wall + ghc-options: -Wall -O2 else - ghc-options: -Wall -Werror + ghc-options: -Wall -Werror -O1 exposed-modules: Urbit.Ob @@ -107,3 +107,16 @@ Test-suite co , text , urbit-hob +benchmark ob-bench + type: exitcode-stdio-1.0 + hs-source-dirs: bench + main-is: Ob.hs + default-language: Haskell2010 + ghc-options: + -rtsopts -O2 + build-depends: + base + , criterion + , deepseq + , urbit-hob +