Module: ActiveRdfBenchmark

Defined in:
lib/active_rdf_helpers.rb

Instance Method Summary collapse

Instance Method Details

#benchmark(title, log_level = Logger::DEBUG, message = '') ⇒ Object

Benchmarking for ActiveRecord. You may pass a message with additional information - there’s a little hack that the “real” benchmark will pass the message to the block, while the “non-benchmark” call will pass nil. This allows you to build the message in the block only if you need it.



51
52
53
54
55
56
57
58
59
60
# File 'lib/active_rdf_helpers.rb', line 51

def benchmark(title, log_level = Logger::DEBUG, message = '')
  if(ActiveRdfLogger.logger.level <= log_level)
    result = nil
    seconds = Benchmark.realtime { result = yield(message) }
    ActiveRdfLogger.log_add("\033[31m\033[1m#{title}\033[0m (#{'%.5f' % seconds}) -- \033[34m#{message}\033[0m", log_level, self)
    result
  else
    yield(nil)
  end
end