Skip to content

Commit 1657962

Browse files
committed
Reasoning and benchmark for the default to max_sample_size 1M.
1 parent 581d1d7 commit 1657962

File tree

3 files changed

+102
-14
lines changed

3 files changed

+102
-14
lines changed

lib/benchee/configuration.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ defmodule Benchee.Configuration do
4040
measure_function_call_overhead: false,
4141
title: nil,
4242
profile_after: false,
43+
# Why a million? Well, it's a nice number :P
44+
# Seriously, though: That's usually enough samples to be significant enough as a
45+
# result.
46+
# At the same time, at least on my machine it takes less than one second for
47+
# `Statistex` to calculate the statistics for a list that large.
48+
# It also generates less than 1GB in data (some of which is garbage collected/
49+
# not necessarily all in RAM at the same time) - which seems reasonable enough.
50+
# see `samples/statistics_performance.exs` and also maybe run it yourself.
4351
max_sample_size: 1_000_000
4452

4553
@typedoc """

samples/sort_performance.exs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,55 @@
11
list_10k = 1..10_000 |> Enum.to_list() |> Enum.shuffle()
22
list_100k = 1..100_000 |> Enum.to_list() |> Enum.shuffle()
3+
list_1M = 1..1_000_000 |> Enum.to_list() |> Enum.shuffle()
34

4-
Benchee.run(%{"10k" => fn -> Enum.sort(list_10k) end, "100k" => fn -> Enum.sort(list_100k) end})
5+
Benchee.run(
6+
[
7+
{"10k", fn -> Enum.sort(list_10k) end},
8+
{"100k", fn -> Enum.sort(list_100k) end},
9+
{"1M", fn -> Enum.sort(list_1M) end}
10+
],
11+
memory_time: 2
12+
)
513

14+
# tobi@qiqi:~/github/benchee(max-sample-size)$ mix run samples/sort_performance.exs
615
# Operating System: Linux
7-
# CPU Information: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
8-
# Number of Available Cores: 8
9-
# Available memory: 15.61 GB
10-
# Elixir 1.8.1
11-
# Erlang 21.3.2
16+
# CPU Information: AMD Ryzen 9 5900X 12-Core Processor
17+
# Number of Available Cores: 24
18+
# Available memory: 31.26 GB
19+
# Elixir 1.18.3
20+
# Erlang 27.3.2
21+
# JIT enabled: true
1222

1323
# Benchmark suite executing with the following configuration:
1424
# warmup: 2 s
1525
# time: 5 s
16-
# memory time: 0 ns
26+
# memory time: 2 s
27+
# reduction time: 0 ns
1728
# parallel: 1
1829
# inputs: none specified
19-
# Estimated total run time: 14 s
30+
# Estimated total run time: 27 s
2031

21-
# Benchmarking 100k...
22-
# Benchmarking 10k...
32+
# Benchmarking 10k ...
33+
# Benchmarking 100k ...
34+
# Benchmarking 1M ...
35+
# Calculating statistics...
36+
# Formatting results...
2337

2438
# Name ips average deviation median 99th %
25-
# 10k 722.79 1.38 ms ±10.21% 1.37 ms 1.77 ms
26-
# 100k 56.70 17.64 ms ±6.38% 17.34 ms 22.84 ms
39+
# 10k 1237.97 0.81 ms ±28.70% 0.73 ms 1.42 ms
40+
# 100k 74.50 13.42 ms ±40.13% 10.96 ms 31.42 ms
41+
# 1M 6.17 162.05 ms ±34.38% 146.08 ms 328.83 ms
2742

2843
# Comparison:
29-
# 10k 722.79
30-
# 100k 56.70 - 12.75x slower +16.25 ms
44+
# 10k 1237.97
45+
# 100k 74.50 - 16.62x slower +12.62 ms
46+
# 1M 6.17 - 200.61x slower +161.24 ms
47+
48+
# Memory usage statistics:
49+
50+
# Name Memory usage
51+
# 10k 1.42 MB
52+
# 100k 18.59 MB - 13.09x memory usage +17.17 MB
53+
# 1M 218.22 MB - 153.62x memory usage +216.80 MB
54+
55+
# **All measurements for memory usage were the same**

samples/statistics_performance.exs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
list_10k = 1..10_000 |> Enum.to_list() |> Enum.shuffle()
2+
list_100k = 1..100_000 |> Enum.to_list() |> Enum.shuffle()
3+
list_1M = 1..1_000_000 |> Enum.to_list() |> Enum.shuffle()
4+
5+
Benchee.run(
6+
[
7+
{"10k", fn -> Statistex.statistics(list_10k) end},
8+
{"100k", fn -> Statistex.statistics(list_100k) end},
9+
{"1M", fn -> Statistex.statistics(list_1M) end}
10+
],
11+
memory_time: 2
12+
)
13+
14+
# tobi@qiqi:~/github/benchee(max-sample-size)$ mix run samples/sort_performance.exs
15+
# Operating System: Linux
16+
# CPU Information: AMD Ryzen 9 5900X 12-Core Processor
17+
# Number of Available Cores: 24
18+
# Available memory: 31.26 GB
19+
# Elixir 1.18.3
20+
# Erlang 27.3.2
21+
# JIT enabled: true
22+
23+
# Benchmark suite executing with the following configuration:
24+
# warmup: 2 s
25+
# time: 5 s
26+
# memory time: 2 s
27+
# reduction time: 0 ns
28+
# parallel: 1
29+
# inputs: none specified
30+
# Estimated total run time: 27 s
31+
32+
# Benchmarking 10k ...
33+
# Benchmarking 100k ...
34+
# Benchmarking 1M ...
35+
# Calculating statistics...
36+
# Formatting results...
37+
38+
# Name ips average deviation median 99th %
39+
# 10k 1237.97 0.81 ms ±28.70% 0.73 ms 1.42 ms
40+
# 100k 74.50 13.42 ms ±40.13% 10.96 ms 31.42 ms
41+
# 1M 6.17 162.05 ms ±34.38% 146.08 ms 328.83 ms
42+
43+
# Comparison:
44+
# 10k 1237.97
45+
# 100k 74.50 - 16.62x slower +12.62 ms
46+
# 1M 6.17 - 200.61x slower +161.24 ms
47+
48+
# Memory usage statistics:
49+
50+
# Name Memory usage
51+
# 10k 1.42 MB
52+
# 100k 18.59 MB - 13.09x memory usage +17.17 MB
53+
# 1M 218.22 MB - 153.62x memory usage +216.80 MB
54+
55+
# **All measurements for memory usage were the same**

0 commit comments

Comments
 (0)