{"id":28630948,"url":"https://github.com/piotrmurach/benchmark-perf","last_synced_at":"2025-06-12T13:09:26.245Z","repository":{"id":62355192,"uuid":"50250295","full_name":"piotrmurach/benchmark-perf","owner":"piotrmurach","description":"Benchmark execution time and iterations per second","archived":false,"fork":false,"pushed_at":"2024-03-14T23:22:29.000Z","size":95,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-26T18:51:51.647Z","etag":null,"topics":["benchmark","performance-testing","ruby","rubygem","testing"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piotrmurach.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"piotrmurach"}},"created_at":"2016-01-23T17:48:56.000Z","updated_at":"2024-11-28T16:32:12.000Z","dependencies_parsed_at":"2024-03-15T00:29:35.711Z","dependency_job_id":"827e6926-44a2-413a-aecf-2f8005d8c71d","html_url":"https://github.com/piotrmurach/benchmark-perf","commit_stats":{"total_commits":136,"total_committers":1,"mean_commits":136.0,"dds":0.0,"last_synced_commit":"a566025011f23551d264b0dec42c98ddd72a8039"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/piotrmurach/benchmark-perf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fbenchmark-perf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fbenchmark-perf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fbenchmark-perf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fbenchmark-perf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piotrmurach","download_url":"https://codeload.github.com/piotrmurach/benchmark-perf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fbenchmark-perf/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259470951,"owners_count":22862999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","performance-testing","ruby","rubygem","testing"],"created_at":"2025-06-12T13:09:25.378Z","updated_at":"2025-06-12T13:09:26.219Z","avatar_url":"https://github.com/piotrmurach.png","language":"Ruby","readme":"# Benchmark::Perf\n\n[![Gem Version](https://badge.fury.io/rb/benchmark-perf.svg)][gem]\n[![Actions CI](https://github.com/piotrmurach/benchmark-perf/workflows/CI/badge.svg?branch=master)][gh_actions_ci]\n[![Build status](https://ci.appveyor.com/api/projects/status/wv37qw3x5l9km5kl?svg=true)][appveyor]\n[![Code Climate](https://codeclimate.com/github/piotrmurach/benchmark-perf/badges/gpa.svg)][codeclimate]\n[![Coverage Status](https://coveralls.io/repos/github/piotrmurach/benchmark-perf/badge.svg?branch=master)][coverage]\n[![Inline docs](http://inch-ci.org/github/piotrmurach/benchmark-perf.svg?branch=master)][inchpages]\n\n[gem]: http://badge.fury.io/rb/benchmark-perf\n[gh_actions_ci]: https://github.com/piotrmurach/benchmark-perf/actions?query=workflow%3ACI\n[appveyor]: https://ci.appveyor.com/project/piotrmurach/benchmark-perf\n[codeclimate]: https://codeclimate.com/github/piotrmurach/benchmark-perf\n[coverage]: https://coveralls.io/github/piotrmurach/benchmark-perf?branch=master\n[inchpages]: http://inch-ci.org/github/piotrmurach/benchmark-perf\n\n\u003e Measure execution time and iterations per second.\n\nThe **Benchmark::Perf** is used by [rspec-benchmark](https://github.com/piotrmurach/rspec-benchmark)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'benchmark-perf'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install benchmark-perf\n\n## Contents\n\n* [1. Usage](#1-usage)\n* [2. API](#2-api)\n  * [2.1 Execution time](#21-execution-time)\n  * [2.2 Iterations](#22-iterations)\n\n## 1. Usage\n\nTo see how long it takes to execute a piece of code do:\n\n```ruby\nresult = Benchmark::Perf.cpu { ... }\n```\n\nThe result will have information about:\n\n```ruby\nresult.avg    # =\u003e average time in sec\nresult.stdev  # =\u003e standard deviation in sec\nresult.dt     # =\u003e elapsed time in sec\n```\n\nOr to see how many iterations per second a piece of code takes do:\n\n```ruby\nresult = Benchmark::Perf.ips { ... }\n```\n\nThen you can query result for:\n\n```ruby\nresult.avg    # =\u003e average ips\nresult.stdev  # =\u003e ips stadard deviation\nresult.iter   # =\u003e number of iterations\nresult.dt     # =\u003e elapsed time\n```\n\n## 2. API\n\n### 2.1 Execution time\n\nBy default `1` measurement is taken, and before that `1` warmup cycle is run.\n\nIf you need to change how many measurements are taken, use the `:repeat` option:\n\n```ruby\nresult = Benchmark::Perf.cpu(repeat: 10) { ... }\n```\n\nThen you can query result for the following information:\n\n```ruby\nresult.avg    # =\u003e average time in sec\nresult.stdev  # =\u003e standard deviation in sec\nresult.dt     # =\u003e elapsed time in sec\n```\n\nIncreasing the number of measurements will lead to more stable results at the price of longer runtime.\n\nTo change how many warmup cycles are done before measuring, use `:warmup` option like so:\n\n```ruby\nBenchmark::Perf.cpu(warmup: 2) { ... }\n```\n\nIf you're interested in having debug output to see exact measurements for each measurement sample use the `:io` option and pass alternative stream:\n\n```ruby\nBenchmark::Perf.cpu(io: $stdout) { ... }\n```\n\nBy 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:\n\n```ruby\nBenchmark::Perf.cpu(subprocess: false) { ... }\n```\n\nOr use the environment variable `RUN_IN_SUBPROCESS` to toggle the behaviour.\n\n### 2.2 Iterations\n\nIn order to check how many iterations per second a given code takes do:\n\n```ruby\nreuslt = Benchmark::Perf.ips { ... }\n```\n\nThe result contains measurements that you can query:\n\n```ruby\nresult.avg    # =\u003e average ips\nresult.stdev  # =\u003e ips stadard deviation\nresult.iter   # =\u003e number of iterations\nresult.dt     # =\u003e elapsed time\n```\n\nAlternatively, the result can be deconstructed into variables:\n\n```ruby\navg, stdev, iter, dt = *result\n```\n\nBy default `1` second is spent warming up Ruby VM, you can change this with the `:warmup` option that expects time value in seconds:\n\n```ruby\nBenchmark::Perf.ips(warmup: 1.45) { ... } # 1.45 second\n```\n\nThe measurements are sampled for `2` seconds by default. You can change this value to increase precision using `:time` option:\n\n```ruby\nBenchmark::Perf.ips(time: 3.5) { ... } # 3.5 seconds\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/piotrmurach/benchmark-perf/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Code of Conduct\n\nEveryone interacting in the Strings project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/benchmark-perf/blob/master/CODE_OF_CONDUCT.md).\n\n## Copyright\n\nCopyright (c) 2016 Piotr Murach. See LICENSE for further details.\n","funding_links":["https://github.com/sponsors/piotrmurach"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Fbenchmark-perf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiotrmurach%2Fbenchmark-perf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Fbenchmark-perf/lists"}