Socket
Book a DemoInstallSign in
Socket

benchify

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

benchify

0.2.2
bundlerRubygems
Version published
Maintainers
1
Created
Source

For 0.2.0 you must call #finish to calculate results
execution time is saved with #call, and calculated later with #finish

documentation will be added ...

Benchify

Gem Version

Benchmark measures for different languages. Compare scripts created in Ruby, Python, Bash... or check different methods execution time in Ruby source code. Benchify count only a real execution time, in seconds. You can set a default count-type, but anyway you'll be able to access values in seconds, milliseconds, minutes and hours. You can also get a time when operation started/ended. Purpose of this is to get an easy way to count anything you do in terminal, including shell commands like sudo apt update.

How to install

Install from rubygems:

gem install benchify

# or add to Gemfile, followed by bundle install
gem 'benchify', '~> 0.1.1'

Install from source:

git clone https://github.com/decentralizuj/benchify
cd benchify

# no dependecies needed for production, only bundler and rake for development
bundle install

How to use

Benchmark Ruby Source-Code:

Initialize new object with type and message (both are optional). Default type is :sec, and message is processed time. Here's a list of available symbols for type, anything else would lead to counting in seconds.

hours        => :h, :hour, :hours
minutes      => :m, :min, :minute, :minutes
milliseconds => :ms, :milli, :milliseconds

benchmark = Benchify.new(:ms)

You can override default message constant, if you want to

Benchify::MESSAGE = 'Your Message Here'

# or you can add a message with new object

benchmark = Benchify.new( :ms, 'Your Message Here' )

Now you can call method #call or it's alias #measure

  benchmark.call { YOUR CODE HERE }
  
  # or
  
  benchmark.measure do
    # YOUR CODE HERE
  end
  
  # you can also add a message as parameter
  
  benchmark.measure('counting seconds:') do
    # YOUR CODE HERE
  end

Benchmark Terminal:

Make sure your script has shebang (environment defined)

#!/usr/bin/env ruby

# if script is not executable, you'll be asked for permission (and sudo password)

benchify script_1.rb script_2.py script_3.sh

Use -e to benchmark shell commands (use this if you don't have shebang in script)

benchify -e 'sudo apt update' 'gem install moriarty' 'python3 somefile.py'

Example

If you don't like name Benchify, you can also use Benchmark

  benchmark = Benchmark.new :sec, ' counted seconds:'

  benchmark.call { ... }
  benchmark.measure('change_message:') { ... }

  Attributes:

    # after initialization
    benchmark.message     => 'processed time:'
    benchmark.type        => :sec
    
    # after code finished
    
    benchmark.start       => Time.now (when started)
    benchmark.end         => Time.now (when ended)
    benchmark.total       => Total seconds (float)
    benchmark.time        => counted time by type (in_seconds)
    benchmark.result      => message + time + type (processed time: 22.124 sec)
    
    # available time attributes (after code finished)
    
    benchmark.in_seconds  => access time in seconds
    benchmark.in_minutes  => access time in minutes
    benchmark.in_hours    => access time in hours
    benchmark.in_ms       => access time in milliseconds

TO-DO

  • Documentation
  • Save output
  • Self methods ( ms, seconds, minutes, hours )

FAQs

Package last updated on 18 Apr 2021

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.