我正在使用Benchee基准的 warmup 属性,逐渐增加了预热时间。我原本希望通过更长的预热时间可以获得更好的结果,但结果却相反。
例如,运行以下示例(从Benchee文档中提取):
list = Enum.to_list(1..10_000)
map_fun = fn i -> [i, i * i] end
Benchee.run(
%{"flat_map" => fn -> Enum.flat_map(list, map_fun) end},
warmup: 0,
)
Benchee.run(
%{"flat_map" => fn -> Enum.flat_map(list, map_fun) end},
warmup: 2,
)
Benchee.run(
%{"flat_map" => fn -> Enum.flat_map(list, map_fun) end},
warmup: 4,
)
Benchee.run(
%{"flat_map" => fn -> Enum.flat_map(list, map_fun) end},
warmup: 8,
)
Benchee.run(
%{"flat_map" => fn -> Enum.flat_map(list, map_fun) end},
warmup: 16,
)
我对上述脚本进行了多次调用,并且得到了相似的结果。第一次执行预热:0是最佳选择。
Operating System: macOS
CPU Information: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Number of Available Cores: 16
Available memory: 32 GB
Elixir 1.10.3
Erlang 23.0.2
Benchmark suite executing with the following configuration:
warmup: 0 ns
time: 5 s
memory time: 0 ns
parallel: 1
inputs: none specified
Estimated total run time: 5 s
Benchmarking flat_map...
Name ips average deviation median 99th %
flat_map 1.70 K 588.45 μs ±14.33% 563 μs 1017.17 μs
Operating System: macOS
CPU Information: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Number of Available Cores: 16
Available memory: 32 GB
Elixir 1.10.3
Erlang 23.0.2
Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 0 ns
parallel: 1
inputs: none specified
Estimated total run time: 7 s
Benchmarking flat_map...
Name ips average deviation median 99th %
flat_map 1.67 K 600.24 μs ±18.69% 563 μs 1085.84 μs
Operating System: macOS
CPU Information: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Number of Available Cores: 16
Available memory: 32 GB
Elixir 1.10.3
Erlang 23.0.2
Benchmark suite executing with the following configuration:
warmup: 4 s
time: 5 s
memory time: 0 ns
parallel: 1
inputs: none specified
Estimated total run time: 9 s
Benchmarking flat_map...
Name ips average deviation median 99th %
flat_map 1.66 K 602.44 μs ±18.32% 564 μs 1085.14 μs
Operating System: macOS
CPU Information: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Number of Available Cores: 16
Available memory: 32 GB
Elixir 1.10.3
Erlang 23.0.2
Benchmark suite executing with the following configuration:
warmup: 8 s
time: 5 s
memory time: 0 ns
parallel: 1
inputs: none specified
Estimated total run time: 13 s
Benchmarking flat_map...
Name ips average deviation median 99th %
flat_map 1.65 K 606.06 μs ±17.35% 573.98 μs 1072.98 μs
Operating System: macOS
CPU Information: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Number of Available Cores: 16
Available memory: 32 GB
Elixir 1.10.3
Erlang 23.0.2
Benchmark suite executing with the following configuration:
warmup: 16 s
time: 5 s
memory time: 0 ns
parallel: 1
inputs: none specified
Estimated total run time: 21 s
Benchmarking flat_map...
Name ips average deviation median 99th %
flat_map 1.66 K 601.32 μs ±17.79% 573 μs 1081 μs
通常在其他VM中,在预热阶段之后,您可以获得更好的性能。
BEAM中的预热如何进行?尤其是在Benchee中?
预先感谢, 亨伯托
答案 0 :(得分:0)
warmup
只是做些什么,而只是将您测量的功能运行一段时间而无需计算结果。
benchee 的创建者指出,warmup
概念是针对JIT语言使用的,首先运行代码将对其进行编译并缓存以备将来调用。
warmup
如何影响BEAM中的基准测试结果?这个问题绝对不可能回答,但是让我们尝试在其中找到任何caching
机制:
如果您的代码简单明了,笨拙且受线程| CPU的限制,warmup
只会给您的CPU增加一定程度,并使您的散热系统更努力地工作,而不会显示任何健全性结果。