Guest User

Untitled

a guest
May 24th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #!/usr/bin/env ruby -w
  2.  
  3. require "benchmark"
  4.  
  5. TESTS = 1_000_000
  6. Benchmark.bmbm do |results|
  7. results.report("a block:") { TESTS.times {
  8. ("a".."z").map { |l| l.capitalize }
  9. } }
  10. results.report("Symbol#to_proc:") { TESTS.times {
  11. ("a".."z").map(&:capitalize)
  12. } }
  13. end
  14.  
  15. # $ ruby_dev -v block_speed.rb
  16. # ruby 1.9.0 (2008-10-10 revision 0) [i386-darwin9.5.0]
  17. # Rehearsal ---------------------------------------------------
  18. # a block: 19.750000 0.130000 19.880000 ( 20.175337)
  19. # Symbol#to_proc: 19.510000 0.130000 19.640000 ( 20.248905)
  20. # ----------------------------------------- total: 39.520000sec
  21. #
  22. # user system total real
  23. # a block: 19.670000 0.110000 19.780000 ( 20.050430)
  24. # Symbol#to_proc: 19.510000 0.130000 19.640000 ( 19.895247)
Add Comment
Please, Sign In to add comment