Skip to content

A peer-to-peer stack for code collaboration

Benchmarking (#368)

James Haydon22e3dc3356fc
diff --git a/exe/Benchmarks.hs b/exe/Benchmarks.hs
new file mode 100644
index 0000000..246cc02
--- /dev/null
+++ b/exe/Benchmarks.hs
@@ -0,0 +1,33 @@
+module Benchmarks (main) where
+
+import Protolude
+
+import Criterion.Main
+
+import Radicle
+
+steps :: [Text] -> Value
+steps is = runIdentity $ snd <$> foldlM step (pureEnv, Number 0) is
+ where
+ step (s,_) t = do
+ (res_, s') <- interpretWithState "[bench]" t s
+ case res_ of
+ Left e -> panic (show e)
+ Right v -> pure (s', v)
+
+counter :: Int -> Rational
+counter i = unwrap $ steps $
+ [ "(def i (ref 0))"
+ , "(def add (fn [x] (write-ref i (+ (read-ref i) x))))"
+ , "(def eval (fn [expr state] (base-eval (list 'add expr) state)))" ]
+ ++ (show <$> take i (cycle [1..20::Int]))
+ where
+ unwrap (Number r) = r
+ unwrap _ = panic "expecting a number result!"
+
+main :: IO ()
+main = defaultMain [
+ bgroup "counter" [ bench "1000" $ whnf counter 1000
+ , bench "10000" $ whnf counter 10000
+ ]
+ ]
diff --git a/package.yaml b/package.yaml
index 44d4d4d..68aa30b 100644
--- a/package.yaml
+++ b/package.yaml
@@ -191,6 +191,18 @@ executables:
- optparse-applicative
ghc-options: -main-is GithubIssues
+ radicle-benchmark:
+ main: Benchmarks.hs
+ source-dirs: exe/
+ other-modules: []
+ when:
+ - condition: impl(ghcjs)
+ buildable: false
+ dependencies:
+ - radicle
+ - criterion
+ ghc-options: -main-is Benchmarks
+
default-extensions:
- AutoDeriveTypeable
- ConstraintKinds