benchmarkable / README

Aman King 0994751 




















































BENCHMARKABLE
by Aman King 

http://bitbucket.org/amanking/benchmarkable/

A module that allows a class to mention which instance methods to benchmark, and then allows retrieving the benchmark report in csv format from the class's instances. The csv includes the method invocation timestamp, some context description (if provided), the method name along with arguments passed for the invocation, and the number of seconds the method took to execute.

Eg:
class Gateway
  # ...
  def make_request(url)
    url = URI.parse(url)
    Net::HTTP.start(url.host, url.port) {|http|
      http.get('/index.html')
    }
  rescue => error
    puts "Unexpected error: #{error.message}"
  end
  # ...

  include Benchmarkable
  benchmark :make_request
end

gateway = Gateway.new
gateway.make_request('http://www.google.com/')
gateway.make_request('http://www.yahoo.com/')
gateway.make_request('http://www.wikyblog.com/AmanKing/')
File.open('./gateway_performance_report.csv', 'a+') do |file|
  file.puts gateway.benchmark_report.to_csv(:starting_context => 'gateway')
end

Output (in gateway_performance_report.csv):
"2009-09-10T20:13:59+05:30","gateway","make_request http://www.google.com/","0.306514978408813"
"2009-09-10T20:13:59+05:30","gateway","make_request http://www.yahoo.com/","1.08063411712646"
"2009-09-10T20:14:00+05:30","gateway","make_request http://www.wikyblog.com/AmanKing/","2.1521680355072"

(see samples/ajaxy_blog_spec.rb for an example of how to use Benchmarkable to monitor ajax performance using selenium, and look at spec/benchmarkable_spec.rb for more details about the api)

License

   Copyright 2009 Aman King

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.