Skip to content

Instantly share code, notes, and snippets.

@sntran
Created April 26, 2021 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sntran/c08c8cb79166e023b961f3147eb49381 to your computer and use it in GitHub Desktop.
Save sntran/c08c8cb79166e023b961f3147eb49381 to your computer and use it in GitHub Desktop.
Erlang's yEnc benchmarks
# Usage: mix run bench/decode.exs [optional switches]
# Optional switches:
# -z, --size <bytes> - Binary size in bytes to decode (default is 76800)
# -s, --sleep <seconds> - warmup time before real benchmark, in seconds (default is 2)
# -j, --jobs <number> - number of processes to be used for each benchmarking job (default is 1)
# -x, --extended_statistics - whether to show extended statistics
#
# Hit Ctrl+C twice to stop it.
{options, _argv, _invalid} = OptionParser.parse(System.argv(),
aliases: [z: :size, s: :sleep, x: :extended_statistics],
strict: [size: :integer, sleep: :integer, extended_statistics: :boolean]
)
size = options[:size] || 768000
jobs = %{
"yEnc" => &:yEnc.decode/1,
"YEnc" => &YEnc.decode/1,
}
{_microseconds, bufWorst} = :timer.tc(fn() ->
:yEnc.encode(:binary.copy(<<224>>, size))
end)
{_microseconds, bufBest} = :timer.tc(fn() ->
:yEnc.encode(:binary.copy(<<0>>, size))
end)
inputs = %{
"Worst (all escaping)" => bufWorst,
"Best (no escaping)" => bufBest,
"Random" => :yEnc.encode(Enum.at(StreamData.binary(length: size), 1))
}
Benchee.run(jobs,
parallel: options[:jobs] || 1,
warmup: options[:sleep] || 2,
time: 1,
# memory_time: 1,
inputs: inputs,
formatters: [
{
Benchee.Formatters.Console,
extended_statistics: options[:extended_statistics]
}
]
)
Operating System: macOS
CPU Information: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Number of Available Cores: 8
Available memory: 16 GB
Elixir 1.11.3
Erlang 23.2.5
Benchmark suite executing with the following configuration:
warmup: 2 s
time: 1 s
memory time: 0 ns
parallel: 1
inputs: Best (no escaping), Random, Worst (all escaping)
Estimated total run time: 18 s
Benchmarking YEnc with input Best (no escaping)...
Benchmarking YEnc with input Random...
Benchmarking YEnc with input Worst (all escaping)...
Benchmarking yEnc with input Best (no escaping)...
Benchmarking yEnc with input Random...
Benchmarking yEnc with input Worst (all escaping)...
##### With input Best (no escaping) #####
Name ips average deviation median 99th %
YEnc 13.71 72.94 ms ±21.04% 68.20 ms 126.36 ms
yEnc 11.59 86.28 ms ±24.61% 78.43 ms 121.41 ms
Comparison:
YEnc 13.71
yEnc 11.59 - 1.18x slower +13.34 ms
##### With input Random #####
Name ips average deviation median 99th %
yEnc 2.67 0.37 s ±17.94% 0.35 s 0.45 s
YEnc 0.92 1.08 s ±0.00% 1.08 s 1.08 s
Comparison:
yEnc 2.67
YEnc 0.92 - 2.89x slower +0.71 s
##### With input Worst (all escaping) #####
Name ips average deviation median 99th %
yEnc 0.0362 27.65 s ±0.00% 27.65 s 27.65 s
YEnc 0.0302 33.11 s ±0.00% 33.11 s 33.11 s
Comparison:
yEnc 0.0362
YEnc 0.0302 - 1.20x slower +5.46 s
# Usage: mix run bench/encode.exs [optional switches]
# Optional switches:
# -z, --size <bytes> - Binary size in bytes to encode (default is 76800)
# -s, --sleep <seconds> - warmup time before real benchmark, in seconds (default is 2)
# -j, --jobs <number> - number of processes to be used for each benchmarking job (default is 1)
# -x, --extended_statistics - whether to show extended statistics
#
# Hit Ctrl+C twice to stop it.
{options, _argv, _invalid} = OptionParser.parse(System.argv(),
aliases: [z: :size, s: :sleep, x: :extended_statistics],
strict: [size: :integer, sleep: :integer, extended_statistics: :boolean]
)
size = options[:size] || 768000
jobs = %{
"yEnc" => &:yEnc.encode/1,
"YEnc" => &YEnc.encode/1,
}
{_microseconds, bufWorst} = :timer.tc(fn() ->
:binary.copy(<<224>>, size)
end)
{_microseconds, bufBest} = :timer.tc(fn() ->
:binary.copy(<<0>>, size)
end)
inputs = %{
"Worst (all escaping)" => bufWorst,
"Best (no escaping)" => bufBest,
"Random" => Enum.at(StreamData.binary(length: size), 1)
}
Benchee.run(jobs,
parallel: options[:jobs] || 1,
warmup: options[:sleep] || 2,
time: 1,
# memory_time: 1,
inputs: inputs,
formatters: [
{
Benchee.Formatters.Console,
extended_statistics: options[:extended_statistics]
}
]
)
Operating System: macOS
CPU Information: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Number of Available Cores: 8
Available memory: 16 GB
Elixir 1.11.3
Erlang 23.2.5
Benchmark suite executing with the following configuration:
warmup: 2 s
time: 1 s
memory time: 0 ns
parallel: 1
inputs: Best (no escaping), Random, Worst (all escaping)
Estimated total run time: 18 s
Benchmarking YEnc with input Best (no escaping)...
Benchmarking YEnc with input Random...
Benchmarking YEnc with input Worst (all escaping)...
Benchmarking yEnc with input Best (no escaping)...
Benchmarking yEnc with input Random...
Benchmarking yEnc with input Worst (all escaping)...
##### With input Best (no escaping) #####
Name ips average deviation median 99th %
yEnc 8.87 112.74 ms ±11.70% 113.64 ms 137.31 ms
YEnc 7.66 130.60 ms ±31.98% 118.11 ms 241.17 ms
Comparison:
yEnc 8.87
YEnc 7.66 - 1.16x slower +17.86 ms
##### With input Random #####
Name ips average deviation median 99th %
YEnc 8.33 120.02 ms ±11.38% 116.85 ms 142.54 ms
yEnc 6.60 151.54 ms ±20.83% 162.45 ms 199.76 ms
Comparison:
YEnc 8.33
yEnc 6.60 - 1.26x slower +31.52 ms
##### With input Worst (all escaping) #####
Name ips average deviation median 99th %
yEnc 7.29 137.17 ms ±2.58% 136.27 ms 141.76 ms
YEnc 5.94 168.32 ms ±11.94% 159.67 ms 198.26 ms
Comparison:
yEnc 7.29
YEnc 5.94 - 1.23x slower +31.16 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment