Skip to content

Instantly share code, notes, and snippets.

@josevalim
Last active Dec 2, 2020
Embed
What would you like to do?
Mixed maps:intersect_with/3
small_int_list = Enum.to_list(1..10)
medium_int_list = Enum.to_list(1..1000)
large_int_list = Enum.to_list(1..100_000)
small_other_int_list = Enum.to_list(11..20)
medium_other_int_list = Enum.to_list(1001..2000)
large_other_int_list = Enum.to_list(100_001..200_000)
small_bin_list = Enum.map(1..10, fn _ -> :crypto.strong_rand_bytes(10) end)
medium_bin_list = Enum.map(1..1000, fn _ -> :crypto.strong_rand_bytes(10) end)
large_bin_list = Enum.map(1..100_000, fn _ -> :crypto.strong_rand_bytes(10) end)
small_other_bin_list = Enum.map(1..10, fn _ -> :crypto.strong_rand_bytes(10) end)
medium_other_bin_list = Enum.map(1..1000, fn _ -> :crypto.strong_rand_bytes(10) end)
large_other_bin_list = Enum.map(1..100_000, fn _ -> :crypto.strong_rand_bytes(10) end)
Benchee.run(
%{
# "cerl_sets (filter)" =>
# {fn [arg1, arg2] -> :fast_maps.filter_based(arg1, arg2) end,
# before_scenario: fn args -> Enum.map(args, &:cerl_sets.from_list/1) end},
# "cerl_sets (iterator)" =>
# {fn [arg1, arg2] -> :fast_maps.iterator_based(arg1, arg2) end,
# before_scenario: fn args -> Enum.map(args, &:cerl_sets.from_list/1) end},
# "cerl_sets (mixed)" =>
# {fn [arg1, arg2] -> :fast_maps.mixed(arg1, arg2) end,
# before_scenario: fn args -> Enum.map(args, &:cerl_sets.from_list/1) end},
"maps (iterator)" =>
{fn [arg1, arg2] -> :maps.intersect(arg1, arg2) end,
before_scenario: fn args -> Enum.map(args, &:cerl_sets.from_list/1) end},
"maps (mixed)" =>
{fn [arg1, arg2] -> :fast_maps.intersect(arg1, arg2) end,
before_scenario: fn args -> Enum.map(args, &:cerl_sets.from_list/1) end},
# "sets" =>
# {fn [arg1, arg2] -> :sets.intersection(arg1, arg2) end,
# before_scenario: fn args -> Enum.map(args, &:sets.from_list/1) end},
# "ordsets" =>
# {fn [arg1, arg2] -> :ordsets.intersection(arg1, arg2) end,
# before_scenario: fn args -> Enum.map(args, &:ordsets.from_list/1) end},
# "gb_sets" =>
# {fn [arg1, arg2] -> :gb_sets.intersection(arg1, arg2) end,
# before_scenario: fn args -> Enum.map(args, &:gb_sets.from_list/1) end}
},
inputs: %{
"small eq int" => [small_int_list, small_int_list],
"medium eq int" => [medium_int_list, medium_int_list],
"large eq int" => [large_int_list, large_int_list],
"small eq bin" => [small_bin_list, small_bin_list],
"medium eq bin" => [medium_bin_list, medium_bin_list],
"large eq bin" => [large_bin_list, large_bin_list],
"small distinct int" => [small_int_list, small_other_int_list],
"medium distinct int" => [medium_int_list, medium_other_int_list],
"large distinct int" => [large_int_list, large_other_int_list],
"small distinct bin" => [small_bin_list, small_other_bin_list],
"medium distinct bin" => [medium_bin_list, medium_other_bin_list],
"large distinct bin" => [large_bin_list, large_other_bin_list],
"large 20%eq bin" => [large_bin_list, Enum.take(large_bin_list, 20_000)],
"large 40%eq bin" => [large_bin_list, Enum.take(large_bin_list, 40_000)],
"large 60%eq bin" => [large_bin_list, Enum.take(large_bin_list, 60_000)],
"large 80%eq bin" => [large_bin_list, Enum.take(large_bin_list, 80_000)],
"large 100%eq bin" => [large_bin_list, large_bin_list],
"large distinct+20%eq bin" => [large_bin_list, large_other_bin_list ++ Enum.take(large_bin_list, 20_000)],
"large distinct+40%eq bin" => [large_bin_list, large_other_bin_list ++ Enum.take(large_bin_list, 40_000)],
"large distinct+60%eq bin" => [large_bin_list, large_other_bin_list ++ Enum.take(large_bin_list, 60_000)],
"large distinct+80%eq bin" => [large_bin_list, large_other_bin_list ++ Enum.take(large_bin_list, 80_000)],
"large distinct+100%eq bin" => [large_bin_list, large_other_bin_list ++ large_bin_list]
},
warmup: 0.5,
time: 3
)
Operating System: macOS
CPU Information: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Number of Available Cores: 8
Available memory: 16 GB
Elixir 1.12.0-dev
Erlang ok
Benchmark suite executing with the following configuration:
warmup: 500 ms
time: 3 s
memory time: 0 ns
parallel: 1
inputs: large 100%eq bin, large 20%eq bin, large 40%eq bin, large 60%eq bin, large 80%eq bin, large distinct bin, large distinct int, large distinct+100%eq bin, large distinct+20%eq bin, large distinct+40%eq bin, large distinct+60%eq bin, large distinct+80%eq bin, large eq bin, large eq int, medium distinct bin, medium distinct int, medium eq bin, medium eq int, small distinct bin, small distinct int, small eq bin, small eq int
Estimated total run time: 2.57 min
Benchmarking maps (iterator) with input large 100%eq bin...
Benchmarking maps (iterator) with input large 20%eq bin...
Benchmarking maps (iterator) with input large 40%eq bin...
Benchmarking maps (iterator) with input large 60%eq bin...
Benchmarking maps (iterator) with input large 80%eq bin...
Benchmarking maps (iterator) with input large distinct bin...
Benchmarking maps (iterator) with input large distinct int...
Benchmarking maps (iterator) with input large distinct+100%eq bin...
Benchmarking maps (iterator) with input large distinct+20%eq bin...
Benchmarking maps (iterator) with input large distinct+40%eq bin...
Benchmarking maps (iterator) with input large distinct+60%eq bin...
Benchmarking maps (iterator) with input large distinct+80%eq bin...
Benchmarking maps (iterator) with input large eq bin...
Benchmarking maps (iterator) with input large eq int...
Benchmarking maps (iterator) with input medium distinct bin...
Benchmarking maps (iterator) with input medium distinct int...
Benchmarking maps (iterator) with input medium eq bin...
Benchmarking maps (iterator) with input medium eq int...
Benchmarking maps (iterator) with input small distinct bin...
Benchmarking maps (iterator) with input small distinct int...
Benchmarking maps (iterator) with input small eq bin...
Benchmarking maps (iterator) with input small eq int...
Benchmarking maps (mixed) with input large 100%eq bin...
Benchmarking maps (mixed) with input large 20%eq bin...
Benchmarking maps (mixed) with input large 40%eq bin...
Benchmarking maps (mixed) with input large 60%eq bin...
Benchmarking maps (mixed) with input large 80%eq bin...
Benchmarking maps (mixed) with input large distinct bin...
Benchmarking maps (mixed) with input large distinct int...
Benchmarking maps (mixed) with input large distinct+100%eq bin...
Benchmarking maps (mixed) with input large distinct+20%eq bin...
Benchmarking maps (mixed) with input large distinct+40%eq bin...
Benchmarking maps (mixed) with input large distinct+60%eq bin...
Benchmarking maps (mixed) with input large distinct+80%eq bin...
Benchmarking maps (mixed) with input large eq bin...
Benchmarking maps (mixed) with input large eq int...
Benchmarking maps (mixed) with input medium distinct bin...
Benchmarking maps (mixed) with input medium distinct int...
Benchmarking maps (mixed) with input medium eq bin...
Benchmarking maps (mixed) with input medium eq int...
Benchmarking maps (mixed) with input small distinct bin...
Benchmarking maps (mixed) with input small distinct int...
Benchmarking maps (mixed) with input small eq bin...
Benchmarking maps (mixed) with input small eq int...
##### With input large 100%eq bin #####
Name ips average deviation median 99th %
maps (mixed) 54.12 18.48 ms ±24.09% 17.85 ms 41.37 ms
maps (iterator) 15.78 63.38 ms ±23.34% 63.69 ms 147.59 ms
Comparison:
maps (mixed) 54.12
maps (iterator) 15.78 - 3.43x slower +44.90 ms
##### With input large 20%eq bin #####
Name ips average deviation median 99th %
maps (mixed) 276.59 3.62 ms ±50.20% 3.34 ms 6.73 ms
maps (iterator) 106.91 9.35 ms ±36.38% 9.22 ms 13.30 ms
Comparison:
maps (mixed) 276.59
maps (iterator) 106.91 - 2.59x slower +5.74 ms
##### With input large 40%eq bin #####
Name ips average deviation median 99th %
maps (mixed) 153.61 6.51 ms ±81.12% 6.53 ms 11.18 ms
maps (iterator) 44.97 22.24 ms ±22.50% 22.45 ms 55.12 ms
Comparison:
maps (mixed) 153.61
maps (iterator) 44.97 - 3.42x slower +15.73 ms
##### With input large 60%eq bin #####
Name ips average deviation median 99th %
maps (mixed) 106.53 9.39 ms ±30.78% 9.22 ms 16.49 ms
maps (iterator) 28.91 34.59 ms ±19.88% 34.81 ms 76.94 ms
Comparison:
maps (mixed) 106.53
maps (iterator) 28.91 - 3.68x slower +25.20 ms
##### With input large 80%eq bin #####
Name ips average deviation median 99th %
maps (mixed) 84.40 11.85 ms ±31.14% 10.80 ms 19.36 ms
maps (iterator) 19.96 50.11 ms ±30.27% 49.80 ms 151.95 ms
Comparison:
maps (mixed) 84.40
maps (iterator) 19.96 - 4.23x slower +38.26 ms
##### With input large distinct bin #####
Name ips average deviation median 99th %
maps (mixed) 131.30 7.62 ms ±70.86% 7.31 ms 14.00 ms
maps (iterator) 127.11 7.87 ms ±36.63% 7.88 ms 11.92 ms
Comparison:
maps (mixed) 131.30
maps (iterator) 127.11 - 1.03x slower +0.25 ms
##### With input large distinct int #####
Name ips average deviation median 99th %
maps (mixed) 170.05 5.88 ms ±24.72% 5.70 ms 8.55 ms
maps (iterator) 160.00 6.25 ms ±32.60% 6.32 ms 9.54 ms
Comparison:
maps (mixed) 170.05
maps (iterator) 160.00 - 1.06x slower +0.37 ms
##### With input large distinct+100%eq bin #####
Name ips average deviation median 99th %
maps (mixed) 75.19 13.30 ms ±27.47% 12.97 ms 17.30 ms
maps (iterator) 16.39 61.00 ms ±20.96% 63.67 ms 119.26 ms
Comparison:
maps (mixed) 75.19
maps (iterator) 16.39 - 4.59x slower +47.70 ms
##### With input large distinct+20%eq bin #####
Name ips average deviation median 99th %
maps (iterator) 103.43 9.67 ms ±63.75% 8.73 ms 15.17 ms
maps (mixed) 95.25 10.50 ms ±60.72% 10.14 ms 18.01 ms
Comparison:
maps (iterator) 103.43
maps (mixed) 95.25 - 1.09x slower +0.83 ms
##### With input large distinct+40%eq bin #####
Name ips average deviation median 99th %
maps (iterator) 79.35 12.60 ms ±57.36% 12.66 ms 19.29 ms
maps (mixed) 78.85 12.68 ms ±25.33% 12.16 ms 19.02 ms
Comparison:
maps (iterator) 79.35
maps (mixed) 78.85 - 1.01x slower +0.0807 ms
##### With input large distinct+60%eq bin #####
Name ips average deviation median 99th %
maps (iterator) 84.22 11.87 ms ±29.30% 11.30 ms 20.86 ms
maps (mixed) 78.18 12.79 ms ±29.78% 11.69 ms 20.58 ms
Comparison:
maps (iterator) 84.22
maps (mixed) 78.18 - 1.08x slower +0.92 ms
##### With input large distinct+80%eq bin #####
Name ips average deviation median 99th %
maps (mixed) 65.21 15.34 ms ±28.38% 15.38 ms 27.15 ms
maps (iterator) 16.24 61.57 ms ±18.95% 63.43 ms 113.70 ms
Comparison:
maps (mixed) 65.21
maps (iterator) 16.24 - 4.02x slower +46.24 ms
##### With input large eq bin #####
Name ips average deviation median 99th %
maps (mixed) 54.63 18.30 ms ±24.60% 17.16 ms 41.70 ms
maps (iterator) 15.54 64.33 ms ±24.44% 64.43 ms 155.29 ms
Comparison:
maps (mixed) 54.63
maps (iterator) 15.54 - 3.51x slower +46.03 ms
##### With input large eq int #####
Name ips average deviation median 99th %
maps (mixed) 70.15 14.26 ms ±24.76% 13.37 ms 22.83 ms
maps (iterator) 16.32 61.27 ms ±22.93% 61.53 ms 132.73 ms
Comparison:
maps (mixed) 70.15
maps (iterator) 16.32 - 4.30x slower +47.01 ms
##### With input medium distinct bin #####
Name ips average deviation median 99th %
maps (mixed) 247.61 K 4.04 μs ±9222.25% 0 μs 0.50 μs
maps (iterator) 197.19 K 5.07 μs ±3408.82% 0 μs 28.50 μs
Comparison:
maps (mixed) 247.61 K
maps (iterator) 197.19 K - 1.26x slower +1.03 μs
##### With input medium distinct int #####
Name ips average deviation median 99th %
maps (mixed) 362.98 K 2.76 μs ±5188.89% 0 μs 0 μs
maps (iterator) 223.00 K 4.48 μs ±3468.72% 0 μs 5.50 μs
Comparison:
maps (mixed) 362.98 K
maps (iterator) 223.00 K - 1.63x slower +1.73 μs
##### With input medium eq bin #####
Name ips average deviation median 99th %
maps (mixed) 29.27 K 34.16 μs ±632.29% 30.50 μs 118.50 μs
maps (iterator) 5.51 K 181.61 μs ±462.18% 206.50 μs 461.75 μs
Comparison:
maps (mixed) 29.27 K
maps (iterator) 5.51 K - 5.32x slower +147.45 μs
##### With input medium eq int #####
Name ips average deviation median 99th %
maps (mixed) 48.66 K 20.55 μs ±1050.00% 8.50 μs 85.50 μs
maps (iterator) 5.44 K 183.78 μs ±169.36% 173.50 μs 373.50 μs
Comparison:
maps (mixed) 48.66 K
maps (iterator) 5.44 K - 8.94x slower +163.23 μs
##### With input small distinct bin #####
Name ips average deviation median 99th %
maps (mixed) 5.17 M 193.55 ns ±21754.86% 0 ns 0 ns
maps (iterator) 3.99 M 250.92 ns ±19648.24% 0 ns 0 ns
Comparison:
maps (mixed) 5.17 M
maps (iterator) 3.99 M - 1.30x slower +57.37 ns
##### With input small distinct int #####
Name ips average deviation median 99th %
maps (iterator) 81.96 M 12.20 ns±143611.14% 0 ns 0 ns
maps (mixed) 5.38 M 185.71 ns ±22014.12% 0 ns 0 ns
Comparison:
maps (iterator) 81.96 M
maps (mixed) 5.38 M - 15.22x slower +173.51 ns
##### With input small eq bin #####
Name ips average deviation median 99th %
maps (mixed) 5.57 M 179.58 ns ±21451.33% 0 ns 0 ns
maps (iterator) 3.77 M 265.53 ns ±18574.58% 0 ns 0 ns
Comparison:
maps (mixed) 5.57 M
maps (iterator) 3.77 M - 1.48x slower +85.96 ns
##### With input small eq int #####
Name ips average deviation median 99th %
maps (mixed) 5.92 M 169.02 ns ±17889.79% 0 ns 0 ns
maps (iterator) 3.59 M 278.80 ns ±17713.63% 0 ns 0 ns
Comparison:
maps (mixed) 5.92 M
maps (iterator) 3.59 M - 1.65x slower +109.78 ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment