Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Measure execution time and iterations per second.
The Benchmark::Perf is used by rspec-benchmark
Add this line to your application's Gemfile:
gem 'benchmark-perf'
And then execute:
$ bundle
Or install it yourself as:
$ gem install benchmark-perf
To see how long it takes to execute a piece of code do:
result = Benchmark::Perf.cpu { ... }
The result will have information about:
result.avg # => average time in sec
result.stdev # => standard deviation in sec
result.dt # => elapsed time in sec
Or to see how many iterations per second a piece of code takes do:
result = Benchmark::Perf.ips { ... }
Then you can query result for:
result.avg # => average ips
result.stdev # => ips stadard deviation
result.iter # => number of iterations
result.dt # => elapsed time
By default 1
measurement is taken, and before that 1
warmup cycle is run.
If you need to change how many measurements are taken, use the :repeat
option:
result = Benchmark::Perf.cpu(repeat: 10) { ... }
Then you can query result for the following information:
result.avg # => average time in sec
result.stdev # => standard deviation in sec
result.dt # => elapsed time in sec
Increasing the number of measurements will lead to more stable results at the price of longer runtime.
To change how many warmup cycles are done before measuring, use :warmup
option like so:
Benchmark::Perf.cpu(warmup: 2) { ... }
If you're interested in having debug output to see exact measurements for each measurement sample use the :io
option and pass alternative stream:
Benchmark::Perf.cpu(io: $stdout) { ... }
By default all measurements are done in subprocess to isolate the measured code from other process activities. Sometimes this may have some unintended consequences. For example, when code uses database connections and transactions, this may lead to lost connections. To switch running in subprocess off, use the :subprocess
option:
Benchmark::Perf.cpu(subprocess: false) { ... }
Or use the environment variable RUN_IN_SUBPROCESS
to toggle the behaviour.
In order to check how many iterations per second a given code takes do:
reuslt = Benchmark::Perf.ips { ... }
The result contains measurements that you can query:
result.avg # => average ips
result.stdev # => ips stadard deviation
result.iter # => number of iterations
result.dt # => elapsed time
Alternatively, the result can be deconstructed into variables:
avg, stdev, iter, dt = *result
By default 1
second is spent warming up Ruby VM, you can change this with the :warmup
option that expects time value in seconds:
Benchmark::Perf.ips(warmup: 1.45) { ... } # 1.45 second
The measurements are sampled for 2
seconds by default. You can change this value to increase precision using :time
option:
Benchmark::Perf.ips(time: 3.5) { ... } # 3.5 seconds
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Everyone interacting in the Strings project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Copyright (c) 2016 Piotr Murach. See LICENSE for further details.
FAQs
Unknown package
We found that benchmark-perf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.