Guest User

Untitled

a guest
Oct 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. require 'ruby-prof'
  2. require 'fileutils'
  3. require 'listen'
  4.  
  5. def write_results(result, type)
  6. FileUtils.mkdir("results") unless File.directory?("results")
  7.  
  8. printer = RubyProf::FlatPrinter.new(result)
  9. printer.print(File.new("results/result-#{type}.txt", "w"))
  10.  
  11. printer = RubyProf::GraphHtmlPrinter.new(result)
  12. printer.print(File.new("results/result-#{type}.html", "w"))
  13.  
  14. printer = RubyProf::DotPrinter.new(result)
  15. printer.print(File.new("results/result-#{type}.dot", "w"))
  16. end
  17.  
  18. def run_test(listener)
  19. t = Thread.new { listener.start }
  20. sleep(0.5)
  21. RubyProf.start
  22. FileUtils.touch 'test'
  23. FileUtils.rm 'test'
  24. Thread.kill(t)
  25. RubyProf.stop
  26. end
  27.  
  28. #####################
  29. # Without FChange
  30. #####################
  31.  
  32. puts "Profiling without fchange"
  33. result = run_test(Listen.to(Dir.pwd, :force_polling => true))
  34. write_results(result, "no-fchange")
  35.  
  36. #####################
  37. # With FChange
  38. #####################
  39.  
  40. puts "Profiling with fchange"
  41. result = run_test(Listen.to(Dir.pwd))
  42. write_results(result, "fchange")
  43.  
  44. puts "Finished profiling"
Add Comment
Please, Sign In to add comment