Benchmarking differnet patterns in OCaml
To do the benchmark on your own machine, clone the repo
$ git clone https://github.com/Isaac-DeFrain/bench.git
$ cd bench
Install dependencies and build
$ opam install --deps-only .
$ dune build
To run the desired benchmarks, uncomment the appropriate line in ./bin/main.ml
and do
$ dune exec -- ./_build/default/bin/main.exe
Here are some interesting discoveries:
- manipulating ADTs is slightly slower than manipulating the correponding GADTs
- pattern matching on ADTs is faster than the corresponding GADTs
Async
functions are faster then theirStdlib
counterparts and significantly faster than theirLwt
counterpartsStdlib
functions are faster than theirBase
library counterparts- tail-recursive list pattern matching is faster than folding over a list
- updating a mutable reference is faster than tail-recursion