Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. require 'benchmark'
  2.  
  3. # Average time using parallel approach 0.014400
  4. # Average time using implemented approach 0.000030
  5.  
  6. PEG = "Peg".freeze
  7. CAR = "Car".freeze
  8. PEGCAR = "Pegcar".freeze
  9.  
  10. def mapp
  11. (1..100).map do |current|
  12. if current % 5 == 0
  13. PEG
  14. elsif current % 7 == 0
  15. CAR
  16. elsif current % 35 == 0
  17. PEGCAR
  18. else
  19. current
  20. end
  21. end
  22. end
  23.  
  24. Benchmark.bm do |b|
  25. b.report { mapp }
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement