Guest User

Untitled

a guest
Jul 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. require 'benchmark'
  2. iterations = 1_000_000
  3.  
  4. words = 'foo, bar, test, boo'.split(',').map(&:strip)
  5. string = 'this is going foo be awesome~!'
  6. Benchmark.bmbm do |bm|
  7. bm.report do
  8. iterations.times do
  9. words.any? { |s| string.include?(s) }
  10. end
  11. end
  12.  
  13. bm.report do
  14. iterations.times do
  15. r = Regexp.union(*words)
  16. r === string
  17. end
  18. end
  19. end
  20. # Rehearsal ------------------------------------
  21. # 0.800000 0.000000 0.800000 ( 0.804023)
  22. # 14.990000 0.020000 15.010000 ( 15.017372)
  23. # -------------------------- total: 15.810000sec
  24.  
  25. # user system total real
  26. # 0.820000 0.000000 0.820000 ( 0.815677)
  27. # 15.020000 0.020000 15.040000 ( 15.039478)
  28.  
  29. Benchmark.bmbm do |bm|
  30. bm.report do
  31. iterations.times do
  32. words = 'foo, bar, test, boo'.split(',').map(&:strip)
  33. string = 'this is going foo be awesome~!'
  34. words.any? { |s| string.include?(s) }
  35. end
  36. end
  37.  
  38. bm.report do
  39. iterations.times do
  40. words = 'foo, bar, test, boo'.split(',').map(&:strip)
  41. string = 'this is going foo be awesome~!'
  42. r = Regexp.union(*words)
  43. r === string
  44. end
  45. end
  46. end
  47. # Rehearsal ------------------------------------
  48. # 4.710000 0.010000 4.720000 ( 4.711062)
  49. # 20.080000 0.000000 20.080000 ( 20.085188)
  50. # -------------------------- total: 24.800000sec
  51.  
  52. # user system total real
  53. # 4.760000 0.000000 4.760000 ( 4.765137)
  54. # 20.130000 0.010000 20.140000 ( 20.142866)
Add Comment
Please, Sign In to add comment