Last active
July 16, 2018 22:36
-
-
Save DavidAntaramian/9bd3d0a0dddbb8bd1e967824647e4c0e to your computer and use it in GitHub Desktop.
Testing the use of inspect/1 with a function yielding an integer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Operating System: macOS" | |
CPU Information: Intel(R) Core(TM) i7-3840QM CPU @ 2.80GHz | |
Number of Available Cores: 8 | |
Available memory: 16 GB | |
Elixir 1.6.4 | |
Erlang 20.3.4 | |
Benchmark suite executing with the following configuration: | |
warmup: 2 s | |
time: 5 s | |
memory time: 0 μs | |
parallel: 1 | |
inputs: none specified | |
Estimated total run time: 28 s | |
Benchmarking with_inspect... | |
Benchmarking with_integer_tostring... | |
Benchmarking with_tostring... | |
Benchmarking without_inspect... | |
Name ips average deviation median 99th % | |
without_inspect 0.62 1.60 s ±6.29% 1.57 s 1.74 s | |
with_integer_tostring 0.41 2.44 s ±5.14% 2.44 s 2.53 s | |
with_tostring 0.35 2.83 s ±1.60% 2.83 s 2.86 s | |
with_inspect 0.0868 11.52 s ±0.00% 11.52 s 11.52 s | |
Comparison: | |
without_inspect 0.62 | |
with_integer_tostring 0.41 - 1.53x slower | |
with_tostring 0.35 - 1.77x slower | |
with_inspect 0.0868 - 7.20x slower |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bench_list = Enum.to_list(1..10_000_000) | |
with_inspect = fn (_) -> inspect(System.system_time(:seconds)) end | |
without_inspect = fn (_) -> System.system_time(:seconds) end | |
with_tostring = fn (_) -> to_string(System.system_time(:seconds)) end | |
with_integer_tostring = fn (_) -> Integer.to_string(System.system_time(:seconds)) end | |
Benchee.run(%{ | |
"with_inspect" => fn -> Enum.each(bench_list, with_inspect) end, | |
"without_inspect" => fn -> Enum.each(bench_list, without_inspect) end, | |
"with_tostring" => fn -> Enum.each(bench_list, with_tostring) end, | |
"with_integer_tostring" => fn -> Enum.each(bench_list, with_integer_tostring) end | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(1)> s = System.monotonic_time(); Enum.each(1..10_000_000, fn (_) -> inspect(System.system_time(:seconds)) end); e = System.monotonic_time() | |
-576460634717908689 | |
iex(2)> System.convert_time_unit((s - e), :native, :milliseconds) | |
-70257 | |
iex(3)> System.convert_time_unit((e - s), :native, :milliseconds) | |
70256 | |
iex(4)> s = System.monotonic_time(); Enum.each(1..10_000_000, fn (_) -> System.system_time(:seconds) end); e = System.monotonic_time() | |
-576460582237370153 | |
iex(5)> System.convert_time_unit((e - s), :native, :milliseconds) | |
10412 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment