Last active
December 23, 2015 06:29
-
-
Save amatsuda/6594242 to your computer and use it in GitHub Desktop.
Want to know how much time you're spending for cleaning database before and after each test?
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
# put this piece of code in your spec/spec_helper.rb or spec/support/any_rb_file.rb | |
# then run `rake spec` | |
module CleanerBench | |
def clean(*) | |
now = Time.now | |
super | |
@time_spent ||= 0 | |
@time_spent += Time.now - now | |
end | |
def clean_with(*) | |
now = Time.now | |
super | |
@time_spent ||= 0 | |
@time_spent += Time.now - now | |
end | |
end | |
DatabaseCleaner.singleton_class.send :prepend, CleanerBench | |
at_exit { p "Spent #{DatabaseCleaner.instance_variable_get(:'@time_spent')} seconds for cleaning database." } | |
#=> 35.698736906051636 seconds under database_cleaner (transaction + truncation if js: true), | |
# 4.483331918716431 seconds under database_rewinder ( https://github.com/amatsuda/database_rewinder ) in my app. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1836 tests in total for a Rails app