on master help sign in
Added bench
commit0ea69da1ca2aa8f0b2861eab87847de7382ad166 authoriko <mail@iko.soy> dateMon 14 Aug 2023, 15:53 (3 years ago) parent255b821
7 files changed+39−29
bench/Main.hs+24−1 exe/Main.hs+1 package.yaml+4 src/Nock.hs+5−6 src/Nock/Jam.hs−1 src/Nock/Parser.hs+4−4 tests/Main.hs+1−17
bench/Main.hs+24−1
@@ -1,3 +1,26 @@
11module Main (main) where
22
3−main = pure ()
3+import Control.Monad
4+import Data.ByteString.Lazy qualified as BSL
5+import Data.Function
6+import Data.Text.Lazy.Encoding as TL
7+import Gauge
8+import Nock
9+import Nock.Parser (noun)
10+import System.FilePath.Posix
11+import System.Process.Typed
12+import Test.Tasty.Golden (findByExtension)
13+
14+main :: IO ()
15+main = do
16+ files <- findByExtension [".hoon"] "tests/golden"
17+ benchmarks <- forM files $ \hoonFile -> do
18+ hoon <- BSL.readFile hoonFile
19+ nock <-
20+ fmap (Nock.Parser.noun . TL.decodeUtf8 . BSL.dropEnd 6 . BSL.drop 11 . snd)
21+ . readProcessStdout
22+ $ proc "urbit" ["eval"]
23+ & setStdin (byteStringInput hoon)
24+ & setStderr nullStream
25+ pure $ bench (takeBaseName hoonFile) $ nf tar $ cell (atom 0) nock
26+ defaultMain benchmarks
exe/Main.hs+1
@@ -1,4 +1,5 @@
11module Main (main) where
22
3+main :: IO ()
34main = pure ()
45
package.yaml+4
@@ -17,6 +17,7 @@ dependencies:
1717 - typed-process
1818 - gauge
1919 - filepath
20+ - deepseq
2021library:
2122 source-dirs: src
2223
@@ -29,6 +30,9 @@ benchmarks:
2930 nock-bench:
3031 main: bench/Main.hs
3132
33+ dependencies:
34+ - tasty
35+ - nock
3236ghc-options: >
3337 -Weverything
3438 -Wno-unsafe
src/Nock.hs+5−6
@@ -2,17 +2,16 @@
22
33module Nock (tar, hax, fas, cell, atom, Annotation (..), Noun, RawNoun (..)) where
44
5+import Control.DeepSeq (NFData)
56import Data.Hashable
6−import Debug.Trace (trace, traceShowId)
77import GHC.Generics (Generic)
8−import GHC.Stack
98import Numeric.Natural
10−import Test.QuickCheck.Arbitrary.Generic
119
1210data Annotation = Annotation
1311 { hash :: Int
1412 }
15− deriving stock (Show)
13+ deriving stock (Show, Generic)
14+ deriving anyclass (NFData)
1615
1716atom :: Natural -> Noun
1817atom nat = Atom nat Annotation {hash = hash nat}
@@ -40,6 +39,7 @@ data RawNoun ann
4039 = Atom !Natural ann
4140 | Cell (RawNoun ann) (RawNoun ann) ann
4241 deriving stock (Generic, Show)
42+ deriving anyclass (NFData)
4343
4444instance Eq (RawNoun ann) where
4545 (Atom lhs _) == (Atom rhs _) = lhs == rhs
@@ -70,8 +70,7 @@ fas ~(Cell ~(Atom lhs _) rhs _) =
7070 case lhs of
7171 1 -> rhs
7272 2 -> case rhs of
73− (Cell lhs' _ _) -> lhs'
74− _ -> undefined
73+ ~(Cell lhs' _ _) -> lhs'
7574 3 -> case rhs of
7675 ~(Cell _ rhs' _) -> rhs'
7776 n
src/Nock/Jam.hs−1
@@ -11,7 +11,6 @@ import Data.Bits
1111import Data.ByteString.Lazy (ByteString)
1212import Data.Map (Map)
1313import Data.Map qualified as M
14−import Data.Word
1514import Nock
1615import Numeric.Natural
1716
src/Nock/Parser.hs+4−4
@@ -3,19 +3,19 @@
33module Nock.Parser (noun) where
44
55import Control.Applicative
6−import Data.Text as T
6+import Data.Text.Lazy as TL
77import Data.Void (Void)
88import Nock
99import Text.Megaparsec
1010import Text.Megaparsec.Char
1111import Text.Megaparsec.Char.Lexer (decimal)
1212
13−noun :: Text -> Noun
14−noun txt = case Text.Megaparsec.parse (space *> parser <* space) "" . T.filter (\c -> c /= '.') $ txt of
13+noun :: TL.Text -> Noun
14+noun txt = case Text.Megaparsec.parse (space *> parser <* space) "" . TL.filter (\c -> c /= '.') $ txt of
1515 Right non -> non
1616 Left err -> error $ errorBundlePretty err
1717
18−type Parser = Parsec Void Text
18+type Parser = Parsec Void TL.Text
1919
2020parser :: Parser Noun
2121parser = try atomParser <|> cellParser
tests/Main.hs+1−17
@@ -1,32 +1,16 @@
11module Main (main) where
22
33import Control.Monad
4−import Data.ByteString qualified as BS
54import Data.ByteString.Lazy qualified as BSL
6−import Data.Char qualified as Char
75import Data.Function
8−import Data.Text as T
9−import Data.Text.Encoding qualified as T
10−import Data.Text.IO as T
11−import Data.Text.Lazy as TL
126import Data.Text.Lazy.Encoding as TL
13−import Data.Text.Lazy.IO as TL
14−import Debug.Trace
15−import Debug.Trace (traceShowId)
16−import GHC.Base (unsafeChr)
177import Nock
18−import Nock.Jam
19−import Nock.Parser
208import Nock.Parser qualified
219import Nock.Printer
2210import System.FilePath.Posix
2311import System.Process.Typed
24−import Test.Hspec
25−import Test.Hspec.QuickCheck
26−import Test.QuickCheck
2712import Test.Tasty
2813import Test.Tasty.Golden
29−import Test.Tasty.Hspec
3014
3115main :: IO ()
3216main = do
@@ -41,7 +25,7 @@ goldenTest = do
4125 pure $ goldenVsString (takeBaseName source) target $ do
4226 hoon <- BSL.readFile source
4327 nock <-
44− fmap (Nock.Parser.noun . T.decodeUtf8 . BS.toStrict . BSL.dropEnd 6 . BSL.drop 11 . snd)
28+ fmap (Nock.Parser.noun . TL.decodeUtf8 . BSL.dropEnd 6 . BSL.drop 11 . snd)
4529 . readProcessStdout
4630 $ proc "urbit" ["eval"]
4731 & setStdin (byteStringInput hoon)