diff --git a/script/bench.rb b/script/bench.rb index ac3be2f36..9dc0949eb 100644 --- a/script/bench.rb +++ b/script/bench.rb @@ -76,11 +76,13 @@ puts "Ensuring profiling DB exists and is migrated" puts `bundle exec rake db:create` `bundle exec rake db:migrate` -puts "Loading Rails" +puts "Timing loading Rails" measure("load_rails") do `bundle exec rake middleware` end +puts "Populating Profile DB" +run("bundle exec ruby script/profile_db_generator.rb") begin pid = spawn("bundle exec thin start -p #{port}") diff --git a/script/profile_db_generator.rb b/script/profile_db_generator.rb index dfd078998..b1ee3b29b 100644 --- a/script/profile_db_generator.rb +++ b/script/profile_db_generator.rb @@ -1,5 +1,16 @@ # can be used to generate a mock db for profiling purposes +# we want our script to generate a consistent output, to do so +# we monkey patch array sample so it always uses the same rng +class Array + RNG = Random.new(1098109928029800) + + def sample + self[RNG.rand(size)] + end +end + + # based on https://gist.github.com/zaius/2643079 def unbundled_require(gem) if defined?(::Bundler) @@ -21,8 +32,9 @@ require 'optparse' begin unbundled_require 'gabbler' rescue LoadError - puts "please run: gem install gabller" - exit + puts "installing gabbler gem" + puts `gem install gabbler` + unbundled_require 'gabbler' end user_id = nil