Benchmark builder

Easily compare execution time of tasks with this very simple online benchmark builder.

loading Benchmark builder
About this tool

What is a benchmark table builder?

When you compare two ways of doing the same thing (a for loop against reduce, one SQL query against another, an old build against a new one), a single timing proves little. The first run is often slower, background work adds noise, and one lucky number can fool you. The usual answer is to measure several times, then compare the mean and look at how spread out the numbers are. This tool does that arithmetic and builds the comparison table for you.

It is important to know what it is not: it does not run your code or time anything. You run the benchmark where it belongs (a browser, Node.js, a database console, a CI job) and type the measurements here. Each suite is one candidate with its list of measurements, in any unit you name (ms, s, ops/s, MB). The tool then sorts the suites with the lowest mean first, shows each one's mean, variance and number of samples, and tells you how far every other suite is from the best, as a difference and as a ratio.

You can add as many suites as you need, name them, and turn on more statistics (median, standard deviation, minimum and maximum). The table can be copied as Markdown, ready for a pull request, a README or an issue, or as a bullet list for a chat message. Your measurements stay in the page and are not uploaded; only the unit and the extended-statistics choice are remembered.

How to compare benchmark results

  1. Start from the two suites already on the page, or add more with the add-suite button. Give each a name that says what it is, such as for loop or reduce.
  2. Type the measurements of each suite. Press Enter after a number to jump to the next field, and Enter on the last one to add a new field. Empty fields are ignored. The trash icon removes a measurement, and the delete button removes the whole suite.
  3. Write the unit in Unit (for example ms). It is only text added to the numbers, so you must use the same unit in every suite.
  4. Read the table. The first row is the suite with the lowest mean. The others show their distance from it, like 10ms (+2.5ms ; x1.333): 2.5 ms slower, 1.333 times the best.
  5. Tick More statistics to add the median, the standard deviation, the minimum and the maximum.
  6. Copy the table as Markdown or as a list. Reset suites goes back to two empty suites.

Examples

The built-in example

Suite 1 has 5 and 10, suite 2 has 8 and 12, in ms:

PositionSuiteMeanVariance
1Suite 17.5ms6.25ms²
2Suite 210ms (+2.5ms ; x1.333)4ms²

Three ways to sum an array

Four runs each, in ms: for loop 12.1, 11.8, 12.4, 12.0; reduce 14.0, 14.4, 13.8, 14.2; map 18.2, 17.9, 18.5, 18.1.

PositionSuiteMeanVariance
1for loop12.075ms0.047ms²
2reduce14.1ms (+2.025ms ; x1.168)0.05ms²
3map18.175ms (+6.1ms ; x1.505)0.047ms²

The gaps between suites are far larger than the variation inside each one, which is what makes the ranking believable.

More statistics

With More statistics on, the for loop row also shows median 12.05ms, standard deviation 0.217ms, minimum 11.8ms and maximum 12.4ms. A median far from the mean warns you about an outlier, such as one slow first run.

A suite without measurements

If a suite has no numbers, it goes to the bottom with a dash and never counts as the best. With A = 100, 102, 98 and an empty B, only A is ranked, with mean 100ms and variance 2.667ms².

Common errors and how to fix them

  • Mixed units: 120 in one suite as milliseconds and 0.12 in another as seconds produce nonsense. Convert them first with the time duration converter.
  • Higher is better, but the table ranks the lowest first: for throughput (ops/s), the tool still puts the lowest mean on top. Read the table from the bottom or measure the time per operation instead.
  • The variance looks smaller than in a spreadsheet: the tool uses the population variance (dividing by the number of samples). For the sample variance, multiply by n and divide by n - 1; with 5 and 10, 6.25 becomes 12.5.

Frequently asked questions

How many runs do I need for a benchmark?

There is no magic number. Run it enough times that the mean stops moving, discard the first runs if they include warm-up, and report the spread as well as the mean. Five to ten runs is a common minimum for quick comparisons.

What is the difference between variance and standard deviation?

Variance is the average squared distance from the mean, so it is in squared units (ms²). The standard deviation is its square root, back in the original unit, which is easier to read. A small value means consistent measurements.

How do I know how much faster one option is?

Use the ratio in the table: x1.505 means 1.505 times the best suite's mean. The tool only organizes measurements; to time something by hand, the chronometer records laps.

How do I see the difference as a percentage?

Put the two means in the percentage calculator, or compare them as a pair in the ratio calculator.

Can I paste the table in GitHub?

Yes. Copy as markdown table produces the | a | b | format that GitHub, GitLab and most documentation tools render as a table.

Collect measurements in code

JavaScript

Run the code several times with performance.now() and keep each duration:

const samples = [];
for (let i = 0; i < 10; i++) {
  const start = performance.now();
  work(); // the code you are measuring
  samples.push(Number((performance.now() - start).toFixed(3)));
}
const mean = samples.reduce((a, b) => a + b, 0) / samples.length;
console.log(samples.join(', '), 'mean:', mean.toFixed(3), 'ms');

Paste the list of samples into a suite.

Python

timeit.repeat returns one total per repetition, and statistics gives the same figures as the tool:

import statistics, timeit

runs = timeit.repeat('sum(range(1000))', number=1000, repeat=5)
print(runs)
print(statistics.mean(runs), statistics.pvariance(runs), statistics.pstdev(runs))

pvariance is the population variance the tool uses; statistics.variance is the sample variance.

Bash

time prints how long a command took; repeat it and note each result:

for i in 1 2 3 4 5; do /usr/bin/time -p ./my-program 2>&1 | grep real; done
Report a problem