Sha256: ec1002753954c2d6ffdf1d9b240ba88b4ffaca96e330b764fb52fcdc5f3c59da

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# Benchmeth

The super easy way to benchmark methods.

```ruby
gem "benchmeth"
```

Just say which methods to benchmark and what you'd like to do with the results.

```ruby
def compute
  puts "CRUNCH!!"
end

benchmeth :compute do |method_name, realtime|
  puts "%s : %.2f ms" % [method_name, realtime * 1000]
  # Or log them.
end

compute

# Output:
# CRUNCH!!
# compute : 0.09 ms
```

To call a method without benchmarking, use:

```ruby
compute_without_benchmark
```

## Instance Methods

```ruby
class Person

  def work(seconds)
    puts "Working for #{seconds} seconds"
    sleep(seconds)
  end

  def play
    puts "Time to play!"
    sleep(rand * 4)
  end

  # This must come after the methods are defined.
  benchmeth :work, :play do |method_name, realtime|
    puts "%s : %.2f ms" % [method_name, realtime * 1000]
  end

end
```

## Class Methods

```ruby
class Person

  def self.count
    2
  end

  class << self
    benchmeth :count do |method_name, realtime|
      puts "%s : %.2f ms" % [method_name, realtime * 1000]
    end
  end

end
```

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
benchmeth-0.0.1 README.md