https://github.com/qqwy/elixir-enum_benchmark_example
Microbenchmark comparing the Elixir iteration abstractions for, enum and iter
https://github.com/qqwy/elixir-enum_benchmark_example
Last synced: 2 months ago
JSON representation
Microbenchmark comparing the Elixir iteration abstractions for, enum and iter
- Host: GitHub
- URL: https://github.com/qqwy/elixir-enum_benchmark_example
- Owner: Qqwy
- Created: 2023-10-07T13:41:12.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-07T15:05:30.000Z (about 2 years ago)
- Last Synced: 2025-02-22T16:07:06.240Z (8 months ago)
- Language: Elixir
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EnumsExample
This tiny repo + benchmark compares a few different approaches to program a little enumeration pipeline which extracts 'tags' from 'posts', to investigate:
- readability
- time efficiency
- memory efficiencyOriginal tweet: https://twitter.com/wojtekmach/status/1710574047703032018
On my machine, running `mix run benchmarks.exs` produces the following output:
```
Compiling 3 files (.ex)
Operating System: macOS
CPU Information: Apple M1 Pro
Number of Available Cores: 10
Available memory: 16 GB
Elixir 1.14.1
Erlang 25.0Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 2 s
parallel: 1
inputs: none specified
Estimated total run time: 45 sBenchmarking FrequenciesMap...
Benchmarking Iter...
Benchmarking Iter (match)...
Benchmarking Original (Enum only)...
Benchmarking Original (for)...Name ips average deviation median 99th %
Iter (match) 257.25 3.89 ms ±10.70% 3.82 ms 4.60 ms
Iter 254.73 3.93 ms ±14.86% 3.81 ms 5.20 ms
Original (for) 232.94 4.29 ms ±10.72% 4.13 ms 5.83 ms
FrequenciesMap 229.46 4.36 ms ±3.65% 4.35 ms 4.88 ms
Original (Enum only) 220.82 4.53 ms ±11.25% 4.37 ms 6.43 msComparison:
Iter (match) 257.25
Iter 254.73 - 1.01x slower +0.0384 ms
Original (for) 232.94 - 1.10x slower +0.41 ms
FrequenciesMap 229.46 - 1.12x slower +0.47 ms
Original (Enum only) 220.82 - 1.16x slower +0.64 msMemory usage statistics:
Name Memory usage
Iter (match) 8.13 MB
Iter 8.13 MB - 1.00x memory usage +0 MB
Original (for) 7.58 MB - 0.93x memory usage -0.55718 MB
FrequenciesMap 10.05 MB - 1.24x memory usage +1.92 MB
Original (Enum only) 6.79 MB - 0.83x memory usage -1.34552 MB**All measurements for memory usage were the same**
```