{"id":13879285,"url":"https://github.com/MatheusRich/benchable","last_synced_at":"2025-07-16T15:31:58.647Z","repository":{"id":56626483,"uuid":"286887462","full_name":"MatheusRich/benchable","owner":"MatheusRich","description":"Write benchmarks without the hassle.","archived":false,"fork":false,"pushed_at":"2025-05-29T19:33:58.000Z","size":51,"stargazers_count":75,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-04T11:54:01.216Z","etag":null,"topics":["benchmark","benchmark-framework","hacktoberfest","ruby"],"latest_commit_sha":null,"homepage":"","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/MatheusRich.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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,"zenodo":null}},"created_at":"2020-08-12T01:36:34.000Z","updated_at":"2025-05-29T19:34:00.000Z","dependencies_parsed_at":"2025-05-29T20:26:45.672Z","dependency_job_id":"9ab695b5-cdad-46d1-8a0b-c4bf6f190370","html_url":"https://github.com/MatheusRich/benchable","commit_stats":{"total_commits":67,"total_committers":2,"mean_commits":33.5,"dds":"0.014925373134328401","last_synced_commit":"bf8e3fd38a6cca2ce19b98acb4c29724f4dee2d2"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/MatheusRich/benchable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatheusRich%2Fbenchable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatheusRich%2Fbenchable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatheusRich%2Fbenchable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatheusRich%2Fbenchable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatheusRich","download_url":"https://codeload.github.com/MatheusRich/benchable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatheusRich%2Fbenchable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265521458,"owners_count":23781512,"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","benchmark-framework","hacktoberfest","ruby"],"created_at":"2024-08-06T08:02:16.203Z","updated_at":"2025-07-16T15:31:58.384Z","avatar_url":"https://github.com/MatheusRich.png","language":"Ruby","readme":"\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003eBenchable\u003c/h1\u003e\n\n  \u003cp align=\"center\"\u003e\n    \u003ci\u003eWrite benchmarks without the hassle.\u003c/i\u003e\n    \u003cbr\u003e\n    \u003cbr\u003e\n    \u003cimg src=\"https://img.shields.io/gem/v/benchable\"\u003e\n    \u003cimg src=\"https://img.shields.io/gem/dt/benchable\"\u003e\n    \u003cimg src=\"https://github.com/MatheusRich/benchable/workflows/Ruby/badge.svg\"\u003e\n    \u003ca href=\"https://github.com/MatheusRich/benchable/blob/master/LICENSE\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/license/MatheusRich/benchable.svg\" alt=\"License\"\u003e\n    \u003c/a\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'benchable'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install benchable\n\n## Usage\n\n### Basic usage\n\nUse the method `Benchable.bench` to declare a benchmark. Write each benchmark case with the `bench` method. The benchmark will run automatically.\n\n```ruby\nBenchable.bench do\n  bench 'sort' do\n    (1..1000000).map { rand }.sort\n  end\n\n  bench 'sort!' do\n    (1..1000000).map { rand }.sort!\n  end\nend\n# Output:\n#                            user     system      total        real\n# Sort                   0.483720   0.003975   0.487695 (  0.487695)\n# Sort!                  0.477415   0.000009   0.477424 (  0.477409)\n```\n\nYou can write a setup method to DRY up any logic.\n\n**Important:** The setup method runs **only once** before **all** benchs, so be careful with mutation inside your benchs.\n\n```ruby\nBenchable.bench do\n  setup do\n    @array = (1..1000000).map { rand }\n  end\n\n  bench 'sort' do\n    @array.dup.sort\n  end\n\n  bench 'sort!' do\n    @array.dup.sort!\n  end\nend\n# Output:\n#                            user     system      total        real\n# Sort                   0.400133   0.011995   0.412128 (  0.412339)\n# Sort!                  0.388636   0.003980   0.392616 (  0.393054)\n```\n\n\u003e We've used `Array#dup` in the example above to prevent the benchmarks for modifying the original array\n\n### Benchmark types\n\nFour benchmark types are available: `bm`, `bmbm`, `ips` and `memory`. You can specify the type by passing it as a symbol on the `Benchable.bench` method. The default type is `bm`.\n\n```ruby\nBenchable.bench(:bm) do\n  # ...\nend\n\nBenchable.bench(:bmbm) do\n  # ...\nend\n\nBenchable.bench(:ips) do\n  # ...\nend\n\nBenchable.bench(:memory) do\n  # ...\nend\n```\n\nYou can also run multiple benchmarks at once:\n\n```ruby\nBenchable.bench(:ips, :memory) do\n  # ...\nend\n```\n\nGiven an invalid benchmark type, Benchable will raise an exception.\n\n```ruby\nBenchable.bench(:invalid) do\n  # ...\nend\n# =\u003e Benchable::Error (Invalid benchmark type 'invalid')\n```\n\n### Benchmark options\n\nYou can provide benchmark options by passing a hash to the `Benchable.bench` method.\n\n#### Options for `Benchmark.bm` and `Benchmark.bmbm`\n\nThe only available option is `width` on `bm` and `bmbm` benchmarks, which specifies the leading spaces for labels on each line. The default width is `20`.\n\n```ruby\nBenchable.bench(width: 25) do\n  # ...\nend\n```\n\n#### Options for `Benchmark::IPS`\n\nIf you're using `::IPS`, you can pass any option accepted by `Benchmark::IPS`'s `config` method.\n\n```ruby\nBenchable.bench(:ips, time: 5, warmup: 2) do\n  # ...\nend\n# Output:\n# Warming up --------------------------------------\n#                 Sort     1.000  i/100ms\n#                Sort!     1.000  i/100ms\n# Calculating -------------------------------------\n#                 Sort      2.114  (± 0.0%) i/s -     11.000  in   5.205127s\n#                Sort!      2.120  (± 0.0%) i/s -     11.000  in   5.189772s\n```\n\n#### Options for `Benchmark::Memory`\n\nYou can pass [any option accepted](https://github.com/michaelherold/benchmark-memory#options) by `Benchmark::Memory`.\n\n```ruby\nBenchable.bench(:memory, quiet: true) do\n  # ...\nend\n# Output:\n# =\u003e #\u003cBenchmark::Memory::Report:0x0000558cdfdbc498 ...\u003e\n\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/MatheusRich/benchable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/MatheusRich/benchable/blob/master/CODE_OF_CONDUCT.md).\n\n## Acknowledgments\n\nThanks [@naomik](https://github.com/naomik) for building the base idea for this in [his gist](https://gist.github.com/naomik/6012505)!\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Benchable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/MatheusRich/benchable/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMatheusRich%2Fbenchable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMatheusRich%2Fbenchable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMatheusRich%2Fbenchable/lists"}