### # Directory watcher needs to be in the directory that this is run from. # You also need a statistics script which is in this directory: # http://benjaminthomas.org/assets/posts/2009-03-12-directory-watcher-algorithms/statistics.rb require 'directory_watcher.rb' require 'statistics.rb' unless $*.length == 1 puts "You must supply one directory to scan" exit end trials = [] NUM_TRIALS = 50 1.upto(NUM_TRIALS) do |i| dw = DirectoryWatcher.new $*[0] dw.glob = '**/*' dw.add_observer { |arg| } start_time = Time.new dw.start dw.stop elapsed_time = Time.new - start_time trials << elapsed_time end # Count files. We don't do this above because we want the test to be as simple as possible. dw = DirectoryWatcher.new $*[0] dw.glob = '**/*' files_counted = 0 dw.add_observer do |arg| files_counted = event.length # if getting passed all events as array # files_counted = files_counted + 1 # if getting passed events 1 at a time end dw.start dw.stop puts "#{$*[0]}" puts "#{'-' * $*[0].length}" puts "Num files: #{files_counted}" puts "Mean #{trials.mean}" puts "Deviation #{trials.deviation}"