# Macro- and Micro-benchmarking in OCaml

*2012-01-01 — idea*


Status: Completed
Level: PartII
Year: 2012
Project: OCaml Labs
Supervisors: Anil Madhavapeddy
Students: Sebastian Funk


Benchmarking involves the measurement of statistics such as run-time, memory allocations, garbage collections in a running program in order to analyze its performance and behaviour. To scientifically evaluate and understand the performance of a program, there is often a cycle of:

1) making performance observations about the program
2) finding a potential hypothesis, i.e. a cause for this performance behaviour
3) making predictions on experiments based on this hypothesis
4) comparing the predictions against the actual benchmark results to evaluate the hypothesis.

To be able to do all this, there is a need for an effective and robust
framework to continuously make these observations that is not biased by the
choice of hypothesis or the observation made.  In general, any sort of
improvement relies on robust and precise measurements.


Benchmarking can be split into two perspectives: micro-benchmarking, measuring
a single (small) function repeatedly to collect statistics for a regression,
and macro-benchmarking, measuring the performance of a complete program or
library, often in a single-run.  This project aims to improve the benchmarking
infrastructure in OCaml, both at micro- and macro-benchmarking.

The project aims to add event tracing into OCaml, via instrumentation to the
[Core Bench](https://github.com/janestreet/core-bench) library using Camlp4.
The event-tracing tool
is then a way for macro-benchmarking together with the multivariate regression
for micro-benchmarking to analyze the performance of commonly used libraries to
exhibit and explain abnormalities and performance differences in
implementations.  On a meta-level this study will give an insight into which
predictors are useful for a multivariate regression in which circumstances to
provide interesting results and how event-tracing can be used efficiently and
compactly in large libraries.

## Related Reading

- [Real World OCaml: Functional Programming for the Masses](https://anil.recoil.org/papers/rwo)

## Links

The dissertation is available on request to students from [Anil Madhavapeddy](https://anil.recoil.org) but isn't
online anywhere. The source code (a CamlP4 event tracer) has been superceded by modern
event tracing.

Sebastian Funk went on to work at Jane Street on OCaml after his project, and one
2019 talk on his subsequent work can be seen below.

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/BysBMdx9w6k?si=8Ll6iVYsK2Q-DHVh" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

## Related

- [Real World OCaml: Functional Programming for the Masses](https://anil.recoil.org/papers/rwo) (paper, 2022-10-01)
  Anil Madhavapeddy, Yaron Minsky

---
Canonical: https://anil.recoil.org/ideas/macro-micro-benchmarking
Type: idea
License: CC BY 4.0 <https://creativecommons.org/licenses/by/4.0/>
Tags: benchmarking, ocaml, janestreet, systems
