Socket
Book a DemoInstallSign in
Socket

benchmark_wrapper

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

benchmark_wrapper

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

BenchmarkWrapper

Build Status Coverage Status Dependency Status

Extend your class to wrap a benchmark around whatever method you want.

Installation

Add this line to your application's Gemfile:

gem 'benchmark_wrapper'

And then execute:

$ bundle

Or install it yourself as:

$ gem install benchmark_wrapper

Usage

  require 'benchmark_wrapper'

  class A
    extend BenchmarkWrapper
    
    def method1; 1; end

    def method2(arg); arg + yield; end

    wrap_with_benchmark :method1, :method2
  end

  a = A.new

  a.method1
  #  0.000000   0.000000   0.000000 (  0.000010)
  # => 1

  a.method2(1) { 1 }
  #  0.000000   0.000000   0.000000 (  0.000008)
  # => 2

It's important to define the methods you want to be benchmarked before you wrap them. The following will not work:

  class A
    extend BenchmarkWrapper

    wrap_with_benchmark :method1
    
    def method1; 1; end
  end
  
  # NameError: undefined method `method1' for class `A'

Output defaults to $stdout but can be redirected:

  RESULTS = []

  class B
    extend BenchmarkWrapper

    def method1; 1; end
   
    wrap_with_benchmark :method1, out: RESULTS, out_method: :<<
  end

  B.new.method1
  # => 1

  RESULTS
  # => [#<Benchmark::Tms ...>]

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

FAQs

Package last updated on 21 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.