add tag
निरंजन
I was comparing the difference between the compilation time of two methods of doing something and the following is my MWE. `\__test_key_bib_ref:nn` is _obviously_ slow, but I still wanted to know it numerically.

```
\documentclass{article}
\usepackage{hyperref}

\ExplSyntaxOn
\seq_gclear_new:N \g_test_bib_seq

\keys_define:nn { test } {
  id
  .tl_set:N         = \l_test_id_tl
}

\cs_new_protected:Npn \__test_key_bib_ref:nn #1#2 {
  \int_incr:N \l_tmpa_int
  \keys_set:nn { test } { #1 }
  \hyperlink { \l_test_id_tl } { #2 }
  \int_use:N \l_tmpa_int
}

\cs_new_protected:Npn \__test_seq_bib_ref:nn #1#2 {
  \int_incr:N \l_tmpb_int
  \hyperlink { bib#1 } { #2 }
  \int_use:N \l_tmpb_int
}

\cs_new_protected:Npn \__test_new_bib_ref:nn #1#2 {
  \keys_set:nn { test } { #1 }
  \seq_gput_right:Ne \g_test_bib_seq {
    \exp_not:N \MakeLinkTarget * {
      \exp_not:V \l_test_id_tl
    } #2
  }
}

\cs_new_protected:Npn \__test_use_bib_ref: {
  \seq_use:Nn \g_test_bib_seq { \par }
}

\cs_gset_eq:NN \keybibref \__test_key_bib_ref:nn
\cs_gset_eq:NN \seqbibref \__test_seq_bib_ref:nn
\cs_gset_eq:NN \newbibref \__test_new_bib_ref:nn
\cs_gset_eq:NN \usebibref \__test_use_bib_ref:
\cs_gset_eq:NN \benchmark \benchmark:n
\ExplSyntaxOff

\begin{document}
\setlength\parindent{0pt}
\benchmark{\keybibref{id=bib1}{foo}\par}

\newpage

\benchmark{\seqbibref{2}{bar}\par}

\newbibref{id=bib1}{A sample reference}
\newbibref{id=bib2}{A sample reference}

\usebibref
\end{document}
```

The results:

```text
\__test_key_bib_ref:nn => 1.77e-4 seconds (887 ops)
\__test_seq_bib_ref:nn => 1.03e-4 seconds (518 ops)
```

This means that it is around 72% faster. But I have some more questions regarding benchmarking itself. Have a look at the output document. The last entry of `\__test_seq_bib_ref:nn` is typeset as `foo909`, whereas for `\__test_key_bib_ref:nn`, it is `bar10301`. What do these numbers mean? If the tool iterates over a function for a set "real" time duration, and the total number of iterations is (around 11 times, in this case) more, then it should be 11 times (i.e., 1100%) more?? What is causing this drastic difference between the number I get in the typeout vs. the number I see in the output document?
Top Answer
Joseph Wright
The `\benchmark:n` function does not carry out a fixed number of cycles. Rather, it runs cycles in increasing numbers until the total run time is over a threshold: the idea is that this reduces the impact of artefacts. So a faster codepath will be run more times (on average) than a slower one in order to give reliable results. You can choose to run only once with `\benchmark_single:n`, but then you have to deal with the issue of accuracy yourself.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.