Skip to content

Instantly share code, notes, and snippets.

@gmccreight
Created March 30, 2014 16:13
Show Gist options
  • Save gmccreight/9875140 to your computer and use it in GitHub Desktop.
Save gmccreight/9875140 to your computer and use it in GitHub Desktop.
#!/bin/bash
ruby_version=2.1.1
folder_name=macvim-rails-speed
gemset=macvim-rails-speed
rails_version=4.0.3
source "$HOME/.rvm/scripts/rvm"
#-----------------------------------------------------------------------------
# Create the $gemset gemset in ruby $ruby_version
#-----------------------------------------------------------------------------
rvm use $ruby_version
rvm --force gemset delete $gemset
rvm gemset create $gemset
rvm use $ruby_version@$gemset
#-----------------------------------------------------------------------------
# Install rails $rails_version
#-----------------------------------------------------------------------------
gem install rails -v=$rails_version --no-rdoc --no-ri
rm -rf $folder_name
rails new $folder_name
#-----------------------------------------------------------------------------
# Add the .ruby-version and .ruby-gemset files
#-----------------------------------------------------------------------------
cd $folder_name
cat << EOF > ./.ruby-version
ruby-$ruby_version
EOF
cat << EOF > ./.ruby-gemset
$gemset
EOF
cd ..
cd $folder_name
# #-----------------------------------------------------------------------------
# # Add factory girl
# #-----------------------------------------------------------------------------
cat << EOF >> Gemfile
group :test do
gem 'factory_girl'
gem 'factory_girl_rails'
gem 'ruby-prof'
end
EOF
bundle
#-----------------------------------------------------------------------------
# Add a user model
#-----------------------------------------------------------------------------
rails generate model user --fixture-replacement=factory_girl
rake db:migrate
rake db:test:prepare
#-----------------------------------------------------------------------------
# Add a test that actually creates a bunch of users using factory girl
#-----------------------------------------------------------------------------
cat << EOF > test/models/user_test.rb
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "the creation speed" do
require 'ruby-prof'
RubyProf.start
x = Time.now
100.times do |i|
FactoryGirl.create :user
if i % 10 == 0
puts Time.now - x
end
end
result = RubyProf.stop
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
end
end
EOF
#-----------------------------------------------------------------------------
# Run rake and output a report
#-----------------------------------------------------------------------------
cd ..
bash -l -c "cd $folder_name; rake | tee speed_report.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment