Entropic Thoughts

Using Nix to Try Tools

Using Nix to Try Tools

Achilleas has a trick where they use curl under hyperfine to do basic benchmarking of web performance. Even if we dislike the methodology, we may be curious what it looks like. However, we may not want to install hyperfine globally on our system just for this one experiment.

This is where a regular person would spin up a container.

Having just started to learn more about Nix, we can try to do it with Nix instead. Nix is a package manager that does not install things globally, but rather brings packages into the environment as requested. This means we can request a shell with hyperfine installed using nix shell.

[kqr@free-p52vh ~]$ nix shell nixpkgs#hyperfine

kqr@free-p52vh:~$ hyperfine --version
hyperfine 1.19.0

kqr@free-p52vh:~$ which hyperfine
/nix/store/chxjl7yxnvqi35k53g1whd6n5km9cpfg-hyperfine-1.19.0/bin/hyperfine

When we run this for the first time, it will take a few seconds to install hyperfine to a separate location and then start a shell with it in the environment.

From here, we can replicate Achilleas technique. However, in this specific case, we don’t even have to open a shell – we can ask Nix to run hyperfine directly instead.

[kqr@free-p52vh ~]$ nix run nixpkgs#hyperfine -- \
  --warmup 10 --min-runs 100 -N \
  "curl https://xkqr.org/fountain/norm"

Benchmark 1: curl https://xkqr.org/fountain/norm
  Time (mean ± σ):      80.4 ms ±   7.1 ms    [User: 14.2 ms, System: 6.1 ms]
  Range (min … max):    67.1 ms … 110.7 ms    100 runs

The more I read about Nix the more I’m convinced it’s a great tool, and I’m glad $day_job forced me to install it so that I can get the benefits of using it in all sorts of contexts! But I do still have much to learn.