Skip to content

Instantly share code, notes, and snippets.

@benoittgt
Created June 9, 2020 21:34
Show Gist options
  • Save benoittgt/3464d476060dbbe1dce5e7c649a3587a to your computer and use it in GitHub Desktop.
Save benoittgt/3464d476060dbbe1dce5e7c649a3587a to your computer and use it in GitHub Desktop.
Final comparison is wrong.
2.2.2: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
2.3.1: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
2.4.6: ruby 2.4.6p354 (2019-04-01 revision 67394) [x86_64-darwin18]
2.5.5: ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin18]
2.6.6: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin18]
2.7.1: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
Calculating -------------------------------------
2.2.2 2.3.1 2.4.6 2.5.5 2.6.6 2.7.1
symbol_to_proc_vs_block
_____
2.2.2
------------------------------[Command output begin]------------------------------
------------------------------[Command output end]------------------------------
ERROR
_____
2.3.1
------------------------------[Script end]------------------------------
$ /Users/bti/.rvm/rubies/ruby-2.3.1/bin/ruby -rbundler/setup /var/folders/n4/62hl6hgj13l65thpl5j_2lbr0000gp/T/benchmark_driver-20200609-11534-1n7l0sx.rb
Ignoring gem-wrappers-1.4.0 because its extensions are not built. Try: gem pristine gem-wrappers --version 1.4.0
/Users/bti/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError)
from /Users/bti/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
------------------------------[Command output begin]------------------------------
------------------------------[Command output end]------------------------------
ERROR
_____
2.4.6
------------------------------[Script end]------------------------------
$ /Users/bti/.rvm/rubies/ruby-2.4.6/bin/ruby -rbundler/setup /var/folders/n4/62hl6hgj13l65thpl5j_2lbr0000gp/T/benchmark_driver-20200609-11534-1jv1dg6.rb
------------------------------[Command output begin]------------------------------
Warming up --------------------------------------
Block map 50.635k i/s - 55.088k times in 1.087946s (19.75μs/i)
Symbol#to_proc map 33.104k i/s - 35.161k times in 1.062148s (30.21μs/i)
Block each 64.363k i/s - 66.290k times in 1.029937s (15.54μs/i)
Symbol#to_proc each 78.807k i/s - 84.788k times in 1.075889s (12.69μs/i)
Calculating -------------------------------------
Block map 47.939k i/s - 151.904k times in 3.168683s (20.86μs/i)
Symbol#to_proc map 59.332k i/s - 99.311k times in 1.673807s (16.85μs/i)
Block each 71.026k i/s - 193.089k times in 2.718568s (14.08μs/i)
Symbol#to_proc each 79.477k i/s - 236.422k times in 2.974739s (12.58μs/i)
Comparison:
Symbol#to_proc each: 79476.6 i/s
Block each: 71026.0 i/s - 1.12x slower
Symbol#to_proc map: 59332.4 i/s - 1.34x slower
Block map: 47939.2 i/s - 1.66x slower
------------------------------[Command output end]------------------------------
_____
2.5.5
------------------------------[Script end]------------------------------
$ /Users/bti/.rvm/rubies/ruby-2.5.5/bin/ruby -rbundler/setup /var/folders/n4/62hl6hgj13l65thpl5j_2lbr0000gp/T/benchmark_driver-20200609-11534-ezx1cd.rb
------------------------------[Command output begin]------------------------------
Warming up --------------------------------------
Block map 58.507k i/s - 61.776k times in 1.055879s (17.09μs/i)
Symbol#to_proc map 39.137k i/s - 45.180k times in 1.154403s (25.55μs/i)
Block each 52.368k i/s - 56.837k times in 1.085336s (19.10μs/i)
Symbol#to_proc each 80.774k i/s - 81.520k times in 1.009236s (12.38μs/i)
Calculating -------------------------------------
Block map 44.635k i/s - 175.520k times in 3.932325s (22.40μs/i)
Symbol#to_proc map 49.232k i/s - 117.411k times in 2.384835s (20.31μs/i)
Block each 62.011k i/s - 157.104k times in 2.533477s (16.13μs/i)
Symbol#to_proc each 86.303k i/s - 242.321k times in 2.807808s (11.59μs/i)
Comparison:
Symbol#to_proc each: 86302.6 i/s
Block each: 62011.2 i/s - 1.39x slower
Symbol#to_proc map: 49232.3 i/s - 1.75x slower
Block map: 44635.2 i/s - 1.93x slower
------------------------------[Command output end]------------------------------
_____
2.6.6
------------------------------[Script end]------------------------------
$ /Users/bti/.rvm/rubies/ruby-2.6.6/bin/ruby -rbundler/setup /var/folders/n4/62hl6hgj13l65thpl5j_2lbr0000gp/T/benchmark_driver-20200609-11534-1ny1z9s.rb
------------------------------[Command output begin]------------------------------
Warming up --------------------------------------
Block map 46.519k i/s - 47.964k times in 1.031069s (21.50μs/i)
Symbol#to_proc map 51.708k i/s - 52.794k times in 1.021001s (19.34μs/i)
Block each 55.427k i/s - 58.437k times in 1.054309s (18.04μs/i)
Symbol#to_proc each 55.216k i/s - 59.392k times in 1.075626s (18.11μs/i)
Calculating -------------------------------------
Block map 55.848k i/s - 139.556k times in 2.498859s (17.91μs/i)
Symbol#to_proc map 59.018k i/s - 155.124k times in 2.628436s (16.94μs/i)
Block each 65.167k i/s - 166.280k times in 2.551596s (15.35μs/i)
Symbol#to_proc each 78.927k i/s - 165.648k times in 2.098739s (12.67μs/i)
Comparison:
Symbol#to_proc each: 78927.4 i/s
Block each: 65167.1 i/s - 1.21x slower
Symbol#to_proc map: 59017.6 i/s - 1.34x slower
Block map: 55847.9 i/s - 1.41x slower
------------------------------[Command output end]------------------------------
_____
2.7.1
------------------------------[Script end]------------------------------
$ /Users/bti/.rvm/rubies/ruby-2.7.1/bin/ruby -rbundler/setup /var/folders/n4/62hl6hgj13l65thpl5j_2lbr0000gp/T/benchmark_driver-20200609-11534-z1ecra.rb
------------------------------[Command output begin]------------------------------
Warming up --------------------------------------
Block map 48.880k i/s - 50.480k times in 1.032727s (20.46μs/i)
Symbol#to_proc map 47.618k i/s - 51.491k times in 1.081342s (21.00μs/i)
Block each 58.927k i/s - 59.770k times in 1.014311s (16.97μs/i)
Symbol#to_proc each 49.140k i/s - 51.732k times in 1.052757s (20.35μs/i)
Calculating -------------------------------------
Block map 44.716k i/s - 146.640k times in 3.279377s (22.36μs/i)
Symbol#to_proc map 49.751k i/s - 142.853k times in 2.871335s (20.10μs/i)
Block each 67.415k i/s - 176.780k times in 2.622248s (14.83μs/i)
Symbol#to_proc each 63.220k i/s - 147.418k times in 2.331816s (15.82μs/i)
Comparison:
Block each: 67415.4 i/s
Symbol#to_proc each: 63220.3 i/s - 1.07x slower
Symbol#to_proc map: 49751.4 i/s - 1.36x slower
Block map: 44715.8 i/s - 1.51x slower
------------------------------[Command output end]------------------------------
0.050 i/s - 1.000 times in 0.000000s 0.000000s 19.316400s 20.897218s 18.877938s 19.977877s
Comparison:
symbol_to_proc_vs_block
2.6.6: 0.1 i/s
2.4.6: 0.1 i/s - 1.02x slower
2.7.1: 0.1 i/s - 1.06x slower
2.5.5: 0.0 i/s - 1.11x slower
2.2.2: 0.0 i/s
2.3.1: 0.0 i/s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment