Sha256: bf25e7674dc6b67bf126bfbcc2941dd411498f4464b5566843129c4592449d08

Contents?: true

Size: 563 Bytes

Versions: 8

Compression:

Stored size: 563 Bytes

Contents

require "redis"
require "benchmark"

module Appstats
  class Benchmarker
  
    attr_accessor :redis
  
    def initialize(data = {})
      @redis = data[:redis] || Redis.new
    end
  
    def measure(title,legend)
      time = Benchmark.measure do
        yield
      end
      record(title,legend,time.real)
      time
    end
  
    def record(title,legend,point)
      redis.multi do
        redis.sadd "benchmarks", title
        redis.sadd "benchmarks:#{title}", legend
        redis.rpush "benchmarks:#{title}:#{legend}", point
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
appstats-0.25.1 lib/appstats/benchmarker.rb
appstats-0.25.0 lib/appstats/benchmarker.rb
appstats-0.24.0 lib/appstats/benchmarker.rb
appstats-0.23.5 lib/appstats/benchmarker.rb
appstats-0.23.4 lib/appstats/benchmarker.rb
appstats-0.23.3 lib/appstats/benchmarker.rb
appstats-0.23.2 lib/appstats/benchmarker.rb
appstats-0.23.1 lib/appstats/benchmarker.rb