-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable tprof #441
Open
PragTob
wants to merge
3
commits into
main
Choose a base branch
from
enable-tprof
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Enable tprof #441
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
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, | ||
"map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten() end | ||
}, | ||
warmup: 0.1, | ||
time: 0.3, | ||
memory_time: 0.3, | ||
profile_after: true | ||
) | ||
|
||
Benchee.run( | ||
%{ | ||
"flat_map" => fn -> Enum.flat_map(list, map_fun) end, | ||
"map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten() end | ||
}, | ||
warmup: 0.1, | ||
time: 0.3, | ||
memory_time: 0.3, | ||
profile_after: :tprof | ||
) | ||
|
||
# tobi@qiqi:~/github/benchee(main)$ mix run samples/fast_with_profiling.exs | ||
# Compiling 2 files (.ex) | ||
# Operating System: Linux | ||
# CPU Information: AMD Ryzen 9 5900X 12-Core Processor | ||
# Number of Available Cores: 24 | ||
# Available memory: 31.26 GB | ||
# Elixir 1.17.3 | ||
# Erlang 27.1 | ||
# JIT enabled: true | ||
|
||
# Benchmark suite executing with the following configuration: | ||
# warmup: 100 ms | ||
# time: 300 ms | ||
# memory time: 300 ms | ||
# reduction time: 0 ns | ||
# parallel: 1 | ||
# inputs: none specified | ||
# Estimated total run time: 1 s 400 ms | ||
|
||
# Benchmarking flat_map ... | ||
# Benchmarking map.flatten ... | ||
# Calculating statistics... | ||
# Formatting results... | ||
|
||
# Name ips average deviation median 99th % | ||
# flat_map 2.24 K 447.25 μs ±53.59% 322.59 μs 1096.32 μs | ||
# map.flatten 1.61 K 620.76 μs ±38.00% 689.02 μs 963.44 μs | ||
|
||
# Comparison: | ||
# flat_map 2.24 K | ||
# map.flatten 1.61 K - 1.39x slower +173.51 μs | ||
|
||
# Memory usage statistics: | ||
|
||
# Name Memory usage | ||
# flat_map 625 KB | ||
# map.flatten 781.25 KB - 1.25x memory usage +156.25 KB | ||
|
||
# **All measurements for memory usage were the same** | ||
|
||
# Profiling flat_map with eprof... | ||
|
||
# Profile results of #PID<0.1617.0> | ||
# # CALLS % TIME µS/CALL | ||
# Total 30004 100.0 3779 0.13 | ||
# Enum.flat_map/2 1 0.00 0 0.00 | ||
# anonymous fn/2 in :elixir_compiler_2.__FILE__/1 1 0.00 0 0.00 | ||
# :erlang.apply/2 1 0.03 1 1.00 | ||
# :erlang.++/2 10000 14.58 551 0.06 | ||
# Enum.flat_map_list/2 10001 42.13 1592 0.16 | ||
# anonymous fn/1 in :elixir_compiler_2.__FILE__/1 10000 43.27 1635 0.16 | ||
|
||
# Profile done over 6 matching functions | ||
|
||
# Profiling map.flatten with eprof... | ||
|
||
# Profile results of #PID<0.1619.0> | ||
# # CALLS % TIME µS/CALL | ||
# Total 60007 100.0 5281 0.09 | ||
# List.flatten/1 1 0.00 0 0.00 | ||
# Enum.map/2 1 0.00 0 0.00 | ||
# :lists.flatten/1 1 0.00 0 0.00 | ||
# :erlang.apply/2 1 0.04 2 2.00 | ||
# anonymous fn/2 in :elixir_compiler_2.__FILE__/1 1 0.04 2 2.00 | ||
# anonymous fn/1 in :elixir_compiler_2.__FILE__/1 10000 19.90 1051 0.11 | ||
# Enum."-map/2-lists^map/1-1-"/2 10001 26.60 1405 0.14 | ||
# :lists.do_flatten/2 40001 53.42 2821 0.07 | ||
|
||
# Profile done over 8 matching functions | ||
# Operating System: Linux | ||
# CPU Information: AMD Ryzen 9 5900X 12-Core Processor | ||
# Number of Available Cores: 24 | ||
# Available memory: 31.26 GB | ||
# Elixir 1.17.3 | ||
# Erlang 27.1 | ||
# JIT enabled: true | ||
|
||
# Benchmark suite executing with the following configuration: | ||
# warmup: 100 ms | ||
# time: 300 ms | ||
# memory time: 300 ms | ||
# reduction time: 0 ns | ||
# parallel: 1 | ||
# inputs: none specified | ||
# Estimated total run time: 1 s 400 ms | ||
|
||
# Benchmarking flat_map ... | ||
# Benchmarking map.flatten ... | ||
# Calculating statistics... | ||
# Formatting results... | ||
|
||
# Name ips average deviation median 99th % | ||
# flat_map 2.42 K 412.87 μs ±48.32% 323.59 μs 737.84 μs | ||
# map.flatten 1.72 K 582.68 μs ±35.48% 673.13 μs 987.99 μs | ||
|
||
# Comparison: | ||
# flat_map 2.42 K | ||
# map.flatten 1.72 K - 1.41x slower +169.81 μs | ||
|
||
# Memory usage statistics: | ||
|
||
# Name Memory usage | ||
# flat_map 625 KB | ||
# map.flatten 781.25 KB - 1.25x memory usage +156.25 KB | ||
|
||
# **All measurements for memory usage were the same** | ||
|
||
# Profiling flat_map with tprof... | ||
|
||
# Profile results of #PID<0.3062.0> | ||
# # CALLS % TIME µS/CALL | ||
# Total 30003 100.00 3686 0.12 | ||
# Enum.flat_map/2 1 0.00 0 0.00 | ||
# anonymous fn/2 in :elixir_compiler_2.__FILE__/1 1 0.05 2 2.00 | ||
# :erlang.++/2 10000 14.46 533 0.05 | ||
# anonymous fn/1 in :elixir_compiler_2.__FILE__/1 10000 33.67 1241 0.12 | ||
# Enum.flat_map_list/2 10001 51.82 1910 0.19 | ||
|
||
# Profile done over 5 matching functions | ||
|
||
# Profiling map.flatten with tprof... | ||
|
||
# Profile results of #PID<0.3064.0> | ||
# # CALLS % TIME µS/CALL | ||
# Total 60006 100.00 5316 0.09 | ||
# List.flatten/1 1 0.00 0 0.00 | ||
# Enum.map/2 1 0.00 0 0.00 | ||
# :lists.flatten/1 1 0.00 0 0.00 | ||
# anonymous fn/2 in :elixir_compiler_2.__FILE__/1 1 0.06 3 3.00 | ||
# anonymous fn/1 in :elixir_compiler_2.__FILE__/1 10000 24.72 1314 0.13 | ||
# Enum."-map/2-lists^map/1-1-"/2 10001 25.81 1372 0.14 | ||
# :lists.do_flatten/2 40001 49.42 2627 0.07 |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is a way to pass opts to the profilers, like
call_memory
totprof
to get heap allocs?https://hexdocs.pm/mix/Mix.Tasks.Profile.Tprof.html#profile/2-options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchee already supports
profile_after: {profiler, opts}
🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely! See https://github.com/bencheeorg/benchee?tab=readme-ov-file#configuration for
profile_after
Should make that clearer/include it in the profiler section of the README though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah didn't see your response, sometimes github auto fetches sometimes it doesn't - but yeah :)