Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add benchmark files

  • Loading branch information...
commit 790953b7a816bb22f82dd84871a3a84d80578894 1 parent 705f322
Maher Sallam authored
11 benchmark/Gemfile
View
@@ -0,0 +1,11 @@
+source :rubygems
+
+gem 'ruby-prof', '0.11.2'
+
+gem 'rb-fchange', '0.0.5'
+
+gem 'win32-changenotify', '0.5.1'
+gem 'win32-event', '0.6.0'
+gem 'em-dir-watcher', '0.9.4'
+
+gem 'wdm', :path => '..'
13 benchmark/config.rb
View
@@ -0,0 +1,13 @@
+module TestConfig
+ # Directory to watch
+ DIR = 'C:\Users\Maher\Desktop\test'
+
+ # Times to run the tests before printing the result
+ REPEAT_COUNT = 10
+
+ # Test duration (in seconds)
+ TEST_DURATION = 30
+
+ # Time between generating events (in seconds)
+ EVENTS_INTERVAL = 0.001
+end
104 benchmark/detecting_changes/benchmark.rb
View
@@ -0,0 +1,104 @@
+require 'thread'
+require 'benchmark'
+
+require 'rb-fchange'
+require 'wdm'
+require 'em-dir-watcher'
+require 'listen'
+
+require_relative './../config.rb'
+
+Thread.abort_on_exception = true
+
+def run_test(options = {})
+ results = []
+ changes = 0
+ callback = Proc.new { changes += 1 }
+
+ puts "Running tests on #{options[:lib_name]}\n"
+
+ options[:instance].send(options[:watch_method] || :watch, TestConfig::DIR, &callback)
+
+ TestConfig::REPEAT_COUNT.times do |i|
+ t = Thread.new { options[:instance].send(options[:run_method] || :run) }
+
+ sleep(TestConfig::TEST_DURATION)
+
+ options[:instance].send(options[:stop_method] || :stop)
+ t.join
+
+ puts "=> Recorded changes in run ##{i+1}: #{changes}"
+
+ results << changes
+ changes = 0
+ end
+
+ puts "\n=> Average recorded changes: #{results.inject(&:+)/TestConfig::REPEAT_COUNT}\n\n"
+end
+
+def run_em_test(options = {})
+ results = []
+ changes = 0
+ callback = Proc.new { changes += 1 }
+
+ puts "Running tests on #{options[:lib_name]}\n"
+
+ TestConfig::REPEAT_COUNT.times do |i|
+ t = Thread.new { EM.run {
+ watcher = options[:module].send(options[:watch_method] || :watch, TestConfig::DIR, &callback)
+ } }
+
+ sleep(TestConfig::TEST_DURATION)
+
+ watcher.send(options[:stop_method] || :stop)
+ sleep(0.2)
+ Thread.kill(t) if t
+
+ puts "=> Recorded changes in run ##{i+1}: #{changes}"
+
+ results << changes
+ changes = 0
+ end
+
+ puts "\n=> Average recorded changes: #{results.reject(&:zero?).inject(&:+)/(TestConfig::REPEAT_COUNT/2)}\n\n"
+end
+
+def run_polling_test
+ results = []
+ changes = 0
+ callback = Proc.new { changes += 1 }
+
+ puts "Running tests on Listen (polling)\n"
+
+ listener = Listen.to(TestConfig::DIR)
+ .force_polling(true)
+ .change(&callback)
+
+ TestConfig::REPEAT_COUNT.times do |i|
+ t = Thread.new { listener.start }
+
+ sleep(TestConfig::TEST_DURATION)
+
+ listener.stop
+ t.join
+
+ puts "=> Recorded changes in run ##{i+1}: #{changes}"
+
+ results << changes
+ changes = 0
+ end
+
+ puts "\n=> Average recorded changes: #{results.inject(&:+)/TestConfig::REPEAT_COUNT}\n\n"
+end
+
+# Setup
+wdm = WDM::Monitor.new
+fchange = FChange::Notifier.new
+
+# Run the test
+Benchmark.bmbm do |x|
+ x.report("FChange") { run_test(lib_name: "FChange", instance: fchange) }
+ x.report("WDM") { run_test(lib_name: "WDM", instance: wdm, run_method: :run!) }
+ x.report("EM-Dir-Watcher") { run_em_test(lib_name: "EM-Dir-Watcher", module: EMDirWatcher) }
+ x.report("Listen (polling)") { run_polling_test }
+end
19 benchmark/detecting_changes/events_generator.rb
View
@@ -0,0 +1,19 @@
+require 'fileutils'
+require 'securerandom'
+
+require_relative './../config.rb'
+
+include FileUtils
+
+files = ['file.txt', 'something.txt', 'foo.txt', 'blah.txt']
+
+loop do
+ begin
+ touch "#{TestConfig::DIR}/#{files[ARGV.first.to_i]}"
+ rescue Errno::EACCES # Happens when the polling test is run!
+ sleep 0.1
+ retry
+ end
+
+ sleep(TestConfig::EVENTS_INTERVAL)
+end
BIN  benchmark/detecting_changes/results.xlsx
View
Binary file not shown
94 benchmark/impact/benchmark.rb
View
@@ -0,0 +1,94 @@
+require 'ruby-prof'
+require 'fileutils'
+
+require 'rb-fchange'
+require 'wdm'
+
+require_relative './../config.rb'
+
+def write_results(result, type)
+ printer = RubyProf::GraphHtmlPrinter.new(result)
+ printer.print(File.new("#{TestConfig::DIR}/result-#{type}.html", "w"))
+end
+
+def run_test
+ 10.times do
+ FileUtils.touch "#{TestConfig::DIR}/file.txt"
+ FileUtils.rm "#{TestConfig::DIR}/file.txt"
+ end
+end
+
+2.times do
+ GC.enable
+ GC.start
+ GC.disable
+
+ #####################
+ # Without FChange
+ #####################
+
+ puts "Profiling ruby"
+
+ # Profile the code
+
+ RubyProf.start
+
+ run_test
+
+ result = RubyProf.stop
+ write_results(result, "ruby")
+
+ #####################
+ # With WDM
+ #####################
+
+ puts "Profiling with wdm"
+
+ monitor = WDM::Monitor.new
+ monitor.watch(TestConfig::DIR, &Proc.new {})
+
+ t = Thread.new { monitor.run! }
+ sleep(0.5)
+
+ # Profile the code
+
+ RubyProf.start
+
+ run_test
+
+ result = RubyProf.stop
+
+ Thread.kill(t)
+
+ # Print results
+
+ write_results(result, "wdm")
+
+ #####################
+ # With FChange
+ #####################
+
+ puts "Profiling with fchange"
+
+ notifier = FChange::Notifier.new
+ notifier.watch(TestConfig::DIR, :all_events, :recursive, &Proc.new {})
+
+ t = Thread.new { notifier.run }
+ sleep(0.5)
+
+ # Profile the code
+
+ RubyProf.start
+
+ run_test
+
+ result = RubyProf.stop
+
+ Thread.kill(t)
+
+ # Print results
+
+ write_results(result, "fchange")
+end
+
+puts "Finished profiling"
BIN  benchmark/impact/results.xlsx
View
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.