Last active
February 17, 2017 15:30
-
-
Save soberstadt/19492b4c1d4617a8ea982f4e114c0833 to your computer and use it in GitHub Desktop.
A script to paste into your rails console to evaluate performance of arbitrary command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# find ruby-prof gem on global scope | |
@ruby_prof_path = `cd .. && gem which ruby-prof` | |
if path.blank? | |
# install ruby-prof if we can't find it | |
`cd .. && gem install ruby-prof` | |
@ruby_prof_path = `cd .. && gem which ruby-prof` | |
end | |
@ruby_prof_path = @ruby_prof_path.sub(/ruby-prof.rb\n/, '') | |
# pull in ruby-prof | |
$LOAD_PATH.push(@ruby_prof_path) && require('ruby-prof') | |
# this is example code to set up my test | |
preloads = [:reverse_contact_assignments, :phone_numbers, :email_addresses, :answer_sheets, :organizational_permissions, :addresses] | |
people = V4::Organization.find(1).people.limit(500).preload(preloads); '' | |
scoper = V4::UserDataScoper.new(V4::Person.find(1)); '' | |
gen = V4::Person::CsvGenerator.new(people, scoper, organization_id: 1); '' | |
result = RubyProf.profile do | |
# run test inside this block | |
gen.generate | |
end | |
# print results to file | |
html_file = File.open('prof.html', 'w') | |
RubyProf::GraphHtmlPrinter.new(result).print(html_file, min_percent: 0) | |
html_file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment