All Projects → klaxit → micro_bench

klaxit / micro_bench

Licence: MIT License
⏰ Dead simple, non intrusive, realtime benchmarks

Programming Languages

ruby
36898 projects - #4 most used programming language
Makefile
30231 projects

Labels

Projects that are alternatives of or similar to micro bench

rop-benchmark
ROP Benchmark is a tool to compare ROP compilers
Stars: ✭ 23 (+76.92%)
Mutual labels:  benchmark
inspec-gke-cis-benchmark
GKE CIS 1.1.0 Benchmark InSpec Profile
Stars: ✭ 27 (+107.69%)
Mutual labels:  benchmark
Turbo-Histogram
Fastest Histogram Construction
Stars: ✭ 44 (+238.46%)
Mutual labels:  benchmark
http bench
golang HTTP stress test tool, support single and distributed
Stars: ✭ 142 (+992.31%)
Mutual labels:  benchmark
serializer-benchmark
A PHP benchmark application to compare PHP serializer libraries
Stars: ✭ 14 (+7.69%)
Mutual labels:  benchmark
go-plugin-benchmark
Benchmark comparing the go plugin package to other plugin implementations
Stars: ✭ 18 (+38.46%)
Mutual labels:  benchmark
latenz
JavaScript HTTP latency analyzer
Stars: ✭ 18 (+38.46%)
Mutual labels:  benchmark
python-performance
Performance benchmarks of Python, Numpy, etc. vs. other languages such as Matlab, Julia, Fortran.
Stars: ✭ 24 (+84.62%)
Mutual labels:  benchmark
minhash-lsh
Minhash LSH in Golang
Stars: ✭ 20 (+53.85%)
Mutual labels:  benchmark
mqtt-mock
mqtt压测工具。支持subscribe、publish压测方式,支持模拟客户端连接数。
Stars: ✭ 78 (+500%)
Mutual labels:  benchmark
elixir port benchmarks
Quick-and-dirty benchmarks for using Ports to communicate with various languages.
Stars: ✭ 24 (+84.62%)
Mutual labels:  benchmark
Unchase.FluentPerformanceMeter
🔨 Make the exact performance measurements of the public methods for public classes using this NuGet Package with fluent interface. Requires .Net Standard 2.0+. It is an Open Source project under Apache-2.0 License.
Stars: ✭ 33 (+153.85%)
Mutual labels:  benchmark
javascript-serialization-benchmark
Comparison and benchmark of JavaScript serialization libraries (Protocol Buffer, Avro, BSON, etc.)
Stars: ✭ 54 (+315.38%)
Mutual labels:  benchmark
npm-yarn-benchmark
Bash script for comparing NPM and Yarn performance
Stars: ✭ 42 (+223.08%)
Mutual labels:  benchmark
node-red-contrib-actionflows
Provides a set of nodes to enable an extendable design pattern for flows.
Stars: ✭ 38 (+192.31%)
Mutual labels:  benchmark
krun
High fidelity benchmark runner
Stars: ✭ 70 (+438.46%)
Mutual labels:  benchmark
jmeter-grpc-plugin
A JMeter plugin supports load test gRPC
Stars: ✭ 36 (+176.92%)
Mutual labels:  benchmark
kubernetes-iperf3
Simple wrapper around iperf3 to measure network bandwidth from all nodes of a Kubernetes cluster
Stars: ✭ 80 (+515.38%)
Mutual labels:  benchmark
p3arsec
Parallel Patterns Implementation of PARSEC Benchmark Applications
Stars: ✭ 12 (-7.69%)
Mutual labels:  benchmark
clj-perf-tips
Clojure performance tips
Stars: ✭ 14 (+7.69%)
Mutual labels:  benchmark

MicroBench

Gem Version CircleCI

gem install micro_bench

Why ?

Ruby Benchmark module is nice but it uses blocks. We see 2 problems to it :

  • if we want to instrument a snippet of code, it breaks git history,
  • variables declared in the benchmark block cannot be used subsequently.

Let's say you want to output the duration of method_1 from :

foo = method_1
method_2(foo)

With Benchmark, we would write something like :

foo = nil
duration = Benchmark.realtime do
  foo = method_1
end
puts "Method 1 duration : #{duration} seconds"
method_2(foo)

With MicroBench, it will look like this :

MicroBench.start
foo = method_1
puts "Method 1 duration : #{MicroBench.duration} seconds"
method_2(foo)

Project maturity

This has been running in production at Klaxit for some months now, but it is still a young library. API may be subject to breaking changes on MINOR versions (but not on PATCH versions).

Install

gem install micro_bench

or in Bundler:

gem "micro_bench"

Usage

Basic usage

require "micro_bench"

MicroBench.start

MicroBench.duration
# 1.628093000501394

MicroBench.duration
# 2.999483000487089

MicroBench.stop
# true

MicroBench.duration
# 5.4341670004651

MicroBench.duration
# 5.4341670004651

Named benchmarks

require "micro_bench"

MicroBench.start("timer1")

MicroBench.stop("timer1")

MicroBench.duration("timer1")
# 1.628093000501394

Multiple starts

Calling .start multiple times with the same bench_id (or none) will cause a "restart" of the given benchmark.

Thread safety

A benchmark is tied to a thread, ensuring that MicroBench is thread-safe. At the same time, it doesn't allow to share a benchmark between multiple threads.

Methods isolation

A benchmark is tied to its calling method so the following code will output 2 separated durations for method_1 and method_2. This prevent collisions when using MicroBench in a large codebase.

def method_1
  MicroBench.start
  method_2
  # Do something
  MicroBench.stop
  puts "method_1 duration : #{MicroBench.duration}"
end

def method_2
  MicroBench.start
  # Do something
  MicroBench.stop
  puts "method_2 duration : #{MicroBench.duration}"
end

method_1

Configuration

You can configure a bit MicroBench to have an even simpler time using it afterwards. Here's how:

MicroBench.configure do |config|
  config.formatter = ->(duration) { "#{duration.round} seconds" }
end

MicroBench.start
sleep 2
MicroBench.duration == "2 seconds"

There are some default formatters that you can set:

id result description
default 722.327823832 the raw original float, for computation
simple 722.33 rounds to 2 digits
mmss "12:02.328" Easy to understand, lossless and compact
human "12 minutes and 2 seconds" For humans, clutters logs

To use one of those, simply write config.formatter = :simple instead of a lambda.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

While still in beta (before 1.0.0), API may be subject to breaking changes on MINOR versions (but not on PATCH versions).

Authors

See the list of contributors who participated in this project.

License

Please see LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].