Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ported simple benchmarking in new base
- Loading branch information
Yehuda Katz + Carl Lerche
committed
May 19, 2009
1 parent
ee5520a
commit 07f733c
Showing
7 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module AbstractController | ||
module Benchmarker | ||
extend ActiveSupport::DependencyModule | ||
|
||
depends_on Logger | ||
|
||
module ClassMethods | ||
def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true) | ||
if logger && logger.level >= log_level | ||
result = nil | ||
ms = Benchmark.ms { result = use_silence ? silence { yield } : yield } | ||
logger.add(log_level, "#{title} (#{('%.1f' % ms)}ms)") | ||
result | ||
else | ||
yield | ||
end | ||
end | ||
|
||
# Silences the logger for the duration of the block. | ||
def silence | ||
old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger | ||
yield | ||
ensure | ||
logger.level = old_logger_level if logger | ||
end | ||
end | ||
end | ||
end |
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
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
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
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