Skip to content

Instantly share code, notes, and snippets.

@searls
Last active Jul 20, 2021
Embed
What would you like to do?
An example of using the time_up gem to investigate performance issues by timing different types of activities. Repo: https://github.com/testdouble/time_up
class ActiveSupport::TestCase
def self.test_data_source(source)
case source
when :test_data
setup do
TestData.load
RefreshesMaterializedViews.new.call
end
teardown do
TestData.rollback
end
when :none
setup do
TestData.truncate
Seeds::SystemConfiguration.seed!
RefreshesMaterializedViews.new.call
end
teardown do
TestData.rollback(:after_data_truncate)
end
else
raise "Valid test_data_source options are :test_data and :none"
end
end
end
at_exit do
TimeUp.print_detailed_summary
end
class ActiveSupport::TestCase
def self.test_data_source(source)
case source
when :test_data
setup do
TimeUp.start(:test_data_load) {
TestData.load
}
TimeUp.start(:refresh_materialized_views) {
RefreshesMaterializedViews.new.call
}
end
teardown do
TimeUp.start(:test_data_rollback) {
TestData.rollback
}
end
when :none
setup do
TimeUp.start(:test_data_truncate) {
TestData.truncate
}
TimeUp.start(:seeds) {
Seeds::SystemConfiguration.seed!
}
TimeUp.start(:refresh_materialized_views) {
RefreshesMaterializedViews.new.call
}
end
teardown do
TimeUp.start(:test_data_rollback_truncate) {
TestData.rollback(:after_data_truncate)
}
end
else
raise "Valid test_data_source options are :test_data and :none"
end
end
end
$ bin/rails test
Run options: --seed 63768
# Running:
.................................................................................................................................................................................
Finished in 6.633458s, 26.6829 runs/s, 68.4409 assertions/s.
177 runs, 454 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Minitest to /Users/justin/code/testdouble/present/coverage. 2791 / 3629 LOC (76.91%) covered.
================================================================================================
Name | Elapsed | Count | Min | Max | Mean | Median | 95th %
------------------------------------------------------------------------------------------------
:test_data_truncate | 0.14966 | 104 | 0.00035 | 0.07013 | 0.00144 | 0.00042 | 0.00155
:seeds | 0.24631 | 104 | 0.00177 | 0.01035 | 0.00237 | 0.00213 | 0.00360
:refresh_materialized_views | 4.20642 | 137 | 0.00971 | 0.06971 | 0.03070 | 0.02786 | 0.06502
:test_data_rollback_truncate | 0.05824 | 104 | 0.00030 | 0.00710 | 0.00056 | 0.00039 | 0.00106
:test_data_load | 0.06444 | 33 | 0.00046 | 0.01064 | 0.00195 | 0.00174 | 0.00247
:test_data_rollback | 0.03282 | 33 | 0.00046 | 0.00170 | 0.00099 | 0.00098 | 0.00134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment