test_benchmarker

A tool for benchmarking ruby Test::Unit tests.


Install
gem install test_benchmarker -v 1.2.1

Documentation

test_benchmarker

test_benchmarker is a ruby library that benchmarks your Test::Unit test. It's intended to help you pinpoint which tests take longer so you can improve the speed of your test suite.

Download

Github: github.com/myronmarston/test_benchmarker

Gem:

gem install test_benchmarker

Usage

Require it in your ruby project:

require 'rubygems'
require 'test_benchmarker'

Or in Rails, with Rails 2.1+ gem support, add to your config/environments/test.rb:

config.gem 'test_benchmarker'

Your tests will only be benchmarked when you set the appropriate environment variable. Use BENCHMARK_TESTS to have get the benchmark tests written to stdout.

When running tests from a single ruby file:

BENCHMARK_TESTS=true ruby path/to/test.rb

Or, when using rake:

rake test BENCHMARK_TESTS=true

Alternately, if you want the test benchmarks written to a file, you can use TEST_BENCHMARKS_FILE:

rake test TEST_BENCHMARKS_FILE=path/to/file

Ruby version compatibility

test_benchmarker works on ruby 1.8.6, 1.8.7 and 1.9.1.

Example Output

test_benchmarker prints two reports:

  1. Class Benchmark Results: Lists each of the Test::Unit::TestCase subclasses in the test run, from the slowest average test time to the fastest.

  2. Test Benchmark Results: Lists each of the tests that ran, from the slowest to the fastest.

Example output (taken from benchmarking will_paginate’s tests):

======                      Class Benchmark Results ===========================
1.    0.027 secs avg time, 1.193 secs total time, 45 tests for: FinderTest
2.    0.005 secs avg time, 0.166 secs total time, 35 tests for: ViewTest
3.    0.001 secs avg time, 0.001 secs total time, 1 tests for: ActiveRecordTestCase
4.    0.000 secs avg time, 0.004 secs total time, 12 tests for: ArrayPaginationTest
5.    0.000 secs avg time, 0.000 secs total time, 1 tests for: WillPaginate::ViewTestCase
======                                                                               ============================ Test Benchmark Results ============================
1.    0.084 secs total time for: test_ability_to_use_with_custom_finders(FinderTest)
2.    0.071 secs total time for: test_paginate_associations(FinderTest)
3.    0.060 secs total time for: test_paginate_with_group(FinderTest)
4.    0.059 secs total time for: test_paginate_in_named_scope_on_has_many_association(FinderTest)
5.    0.058 secs total time for: test_container_id(ViewTest)
6.    0.057 secs total time for: test_paginating_finder_doesnt_mangle_options(FinderTest)
7.    0.057 secs total time for: test_should_use_scoped_finders_if_present(FinderTest)
8.    0.057 secs total time for: test_paginate_with_order(FinderTest)
9.    0.055 secs total time for: test_paginate_by_sql_respects_total_entries_setting(FinderTest)
10.   0.055 secs total time for: test_implicit_all_with_dynamic_finders(FinderTest)
11.   0.052 secs total time for: test_doesnt_remove_referenced_includes_in_count(FinderTest)
12.   0.025 secs total time for: test_paginate_with_include_and_order(FinderTest)
13.   0.024 secs total time for: test_hmt_with_include(FinderTest)
14.   0.023 secs total time for: test_paginate_with_dynamic_finder(FinderTest)
15.   0.022 secs total time for: test_paginate_with_per_page(FinderTest)
16.   0.021 secs total time for: test_paginate_in_named_scope_on_habtm_association(FinderTest)
17.   0.020 secs total time for: test_paginate_with_include_and_conditions(FinderTest)
18.   0.019 secs total time for: test_named_scope_with_include(FinderTest)
19.   0.018 secs total time for: test_paginate_in_named_scope_on_hmt_association(FinderTest)
20.   0.018 secs total time for: test_paginate_with_joins(FinderTest)
21.   0.018 secs total time for: test_paginated_each_with_named_scope(FinderTest)
22.   0.018 secs total time for: test_parameter_api(FinderTest)
23.   0.018 secs total time for: test_readonly(FinderTest)
24.   0.018 secs total time for: test_adding_additional_parameters(ViewTest)
25.   0.017 secs total time for: test_paginate_with_conditions(FinderTest)
26.   0.017 secs total time for: test_paginate_array_of_ids(FinderTest)
27.   0.017 secs total time for: test_paginated_each(FinderTest)
28.   0.017 secs total time for: test_paginate_associations_with_include(FinderTest)
29.   0.016 secs total time for: test_paginate_in_named_scope(FinderTest)
30.   0.016 secs total time for: test_paginate_association_extension(FinderTest)
31.   0.016 secs total time for: test_simple_paginate(FinderTest)
32.   0.016 secs total time for: test_truth(FinderTest)
33.   0.015 secs total time for: test_paginate_by_sql(FinderTest)
34.   0.015 secs total time for: test_count_skips_select(FinderTest)
35.   0.015 secs total time for: test_new_methods_presence(FinderTest)
36.   0.015 secs total time for: test_paginate_by_sql_doesnt_change_original_query(FinderTest)
37.   0.015 secs total time for: test_scoped_paginate(FinderTest)
38.   0.015 secs total time for: test_count_with_scoped_select_when_distinct(FinderTest)
39.   0.014 secs total time for: test_paginate_from(FinderTest)
40.   0.014 secs total time for: test_guessing_the_total_count(FinderTest)
41.   0.014 secs total time for: test_paginate_by_sql_strips_order_by_when_counting(FinderTest)
42.   0.014 secs total time for: test_extra_parameters_stay_untouched(FinderTest)
43.   0.014 secs total time for: test_removes_irrelevant_includes_in_count(FinderTest)
44.   0.013 secs total time for: test_array_argument_doesnt_eliminate_count(FinderTest)
45.   0.013 secs total time for: test_count_and_total_entries_options_are_mutually_exclusive(FinderTest)
46.   0.013 secs total time for: test_count_select_when_distinct(FinderTest)
47.   0.013 secs total time for: test_guessing_that_there_are_no_records(FinderTest)
48.   0.008 secs total time for: test_removing_arbitrary_parameters(ViewTest)
49.   0.005 secs total time for: test_full_output(ViewTest)
50.   0.005 secs total time for: test_will_paginate_windows(ViewTest)
51.   0.004 secs total time for: test_paginated_section(ViewTest)
52.   0.004 secs total time for: test_will_paginate_using_renderer_instance(ViewTest)
53.   0.004 secs total time for: test_will_paginate_eliminates_small_gaps(ViewTest)
54.   0.004 secs total time for: test_custom_routing_with_first_page_hidden(ViewTest)
55.   0.003 secs total time for: test_will_paginate(ViewTest)
56.   0.003 secs total time for: test_will_paginate_with_options(ViewTest)
57.   0.003 secs total time for: test_complex_custom_page_param(ViewTest)
58.   0.003 secs total time for: test_custom_routing_page_param_with_dot_separator(ViewTest)
59.   0.003 secs total time for: test_custom_routing_page_param(ViewTest)
60.   0.003 secs total time for: test_prev_label_deprecated(ViewTest)
61.   0.003 secs total time for: test_will_paginate_with_custom_page_param(ViewTest)
62.   0.003 secs total time for: test_prev_next_links_have_classnames(ViewTest)
63.   0.003 secs total time for: test_adding_additional_route_parameters(ViewTest)
64.   0.003 secs total time for: test_will_paginate_preserves_parameters_on_get(ViewTest)
65.   0.002 secs total time for: test_adding_anchor_parameter(ViewTest)
66.   0.002 secs total time for: test_will_paginate_using_renderer_class(ViewTest)
67.   0.002 secs total time for: test_page_entries_info_with_custom_entry_name(ViewTest)
68.   0.002 secs total time for: test_will_paginate_doesnt_preserve_parameters_on_post(ViewTest)
69.   0.002 secs total time for: test_will_paginate_without_page_links(ViewTest)
70.   0.002 secs total time for: test_will_paginate_without_container(ViewTest)
71.   0.002 secs total time for: test_escaping_of_urls(ViewTest)
72.   0.002 secs total time for: test_deprecation_notices_with_page_count(ViewTest)
73.   0.002 secs total time for: test_page_entries_info_with_single_page_collection(ViewTest)
74.   0.002 secs total time for: test_page_entries_info(ViewTest)
75.   0.002 secs total time for: test_page_entries_info_with_longer_class_name(ViewTest)
76.   0.001 secs total time for: test_collection_name_can_be_guessed(ViewTest)
77.   0.001 secs total time for: test_inferred_collection_name_raises_error_when_nil(ViewTest)
78.   0.001 secs total time for: test_invalid_page(ArrayPaginationTest)
79.   0.001 secs total time for: test_no_pagination_when_page_count_is_one(ViewTest)
80.   0.001 secs total time for: test_paginated_collection(ArrayPaginationTest)
81.   0.001 secs total time for: test_truth(ActiveRecordTestCase)
82.   0.000 secs total time for: test_guessing_total_count(ArrayPaginationTest)
83.   0.000 secs total time for: test_deprecated_api(ArrayPaginationTest)
84.   0.000 secs total time for: test_rescue_response_hook_presence(ViewTest)
85.   0.000 secs total time for: test_argument_error_with_params_and_another_argument(ArrayPaginationTest)
86.   0.000 secs total time for: test_simple(ArrayPaginationTest)
87.   0.000 secs total time for: test_invalid_per_page_setting(ArrayPaginationTest)
88.   0.000 secs total time for: test_page_count_was_removed(ArrayPaginationTest)
89.   0.000 secs total time for: test_no_complain(ViewTest)
90.   0.000 secs total time for: test_no_complain(WillPaginate::ViewTestCase)
91.   0.000 secs total time for: test_previous_next_pages(ArrayPaginationTest)
92.   0.000 secs total time for: test_out_of_bounds(ArrayPaginationTest)
93.   0.000 secs total time for: test_defaults(ArrayPaginationTest)
94.   0.000 secs total time for: test_total_entries_has_precedence(ArrayPaginationTest)
======                                                                             == LICENSE:

(The MIT License)

Copyright © 2009-2010 Myron Marston, Kashless.org

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.