Skip to content

Instantly share code, notes, and snippets.

@stereobooster
Created June 1, 2012 13:11
Show Gist options
  • Save stereobooster/2852056 to your computer and use it in GitHub Desktop.
Save stereobooster/2852056 to your computer and use it in GitHub Desktop.
profile rb-fchange
source :rubygems
gem 'ruby-prof', :git => "https://github.com/wycats/ruby-prof.git"
# gem 'perftools.rb', :git => 'git://github.com/tmm1/perftools.rb.git'
gem 'rb-fchange'
gem 'listen'
require 'ruby-prof'
require 'fileutils'
require 'listen'
def write_results(result, type)
FileUtils.mkdir("results") unless File.directory?("results")
printer = RubyProf::FlatPrinter.new(result)
printer.print(File.new("results/result-#{type}.txt", "w"))
printer = RubyProf::GraphHtmlPrinter.new(result)
printer.print(File.new("results/result-#{type}.html", "w"))
printer = RubyProf::DotPrinter.new(result)
printer.print(File.new("results/result-#{type}.dot", "w"))
end
def run_test(listener)
t = Thread.new { listener.start }
sleep(0.5)
RubyProf.start
FileUtils.touch 'test'
FileUtils.rm 'test'
Thread.kill(t)
RubyProf.stop
end
#####################
# Without FChange
#####################
puts "Profiling without fchange"
result = run_test(Listen.to(Dir.pwd, :force_polling => true))
write_results(result, "no-fchange")
#####################
# With FChange
#####################
puts "Profiling with fchange"
result = run_test(Listen.to(Dir.pwd))
write_results(result, "fchange")
puts "Finished profiling"
require 'fileutils'
require 'listen'
require 'perftools'
#####################
# Without FChange
#####################
puts "Profiling without fchange"
listener = Listen.to(Dir.pwd, :force_polling => true)
t = Thread.new { listener.start }
sleep(0.5)
PerfTools::CpuProfiler.start("result/no-fchange")
FileUtils.touch 'test'
FileUtils.rm 'test'
PerfTools::CpuProfiler.stop
Thread.kill(t)
#####################
# With FChange
#####################
puts "Profiling with fchange"
listener = Listen.to(Dir.pwd)
t = Thread.new { listener.start }
sleep(0.5)
PerfTools::CpuProfiler.start("result/fchange")
FileUtils.touch 'test'
FileUtils.rm 'test'
PerfTools::CpuProfiler.stop
Thread.kill(t)
puts "Finished profiling"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment