{"id":17452464,"url":"https://github.com/pboling/require_bench","last_synced_at":"2025-07-05T03:07:09.189Z","repository":{"id":56891864,"uuid":"149702119","full_name":"pboling/require_bench","owner":"pboling","description":"Benchmark/Timeout/Rescue Ruby's `require`/`load` for Debugging Glory","archived":false,"fork":false,"pushed_at":"2023-10-27T03:39:08.000Z","size":117,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T00:44:45.622Z","etag":null,"topics":["debugging","logging","ruby"],"latest_commit_sha":null,"homepage":"http://railsbling.com/require_bench","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/pboling.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["pboling"],"patreon":"galtzo","ko_fi":"pboling","liberapay":"pboling","issuehunt":"pboling"}},"created_at":"2018-09-21T03:01:49.000Z","updated_at":"2023-10-10T22:19:11.000Z","dependencies_parsed_at":"2023-10-11T00:46:11.221Z","dependency_job_id":"ce3168af-b711-4b1c-b897-b629b737785f","html_url":"https://github.com/pboling/require_bench","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":0.04347826086956519,"last_synced_commit":"0ca78b497e91b6a68f8447870545dab86478a807"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/pboling/require_bench","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pboling%2Frequire_bench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pboling%2Frequire_bench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pboling%2Frequire_bench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pboling%2Frequire_bench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pboling","download_url":"https://codeload.github.com/pboling/require_bench/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pboling%2Frequire_bench/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263674236,"owners_count":23494540,"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":["debugging","logging","ruby"],"created_at":"2024-10-17T23:13:03.587Z","updated_at":"2025-07-05T03:07:09.166Z","avatar_url":"https://github.com/pboling.png","language":"Ruby","funding_links":["https://github.com/sponsors/pboling","https://patreon.com/galtzo","https://ko-fi.com/pboling","https://liberapay.com/pboling","https://issuehunt.io/r/pboling","https://ko-fi.com/O5O86SNP4","https://liberapay.com/pboling/donate"],"categories":[],"sub_categories":[],"readme":"# RequireBench\n\nHave a Ruby project that has stopped loading, and you aren't sure where the issue is?\n\nKnowing the last file that was successfully _required_, or _loaded_ by Ruby can be helpful in diagnosing the issue.  This gem will help you find that last required file.  It can also help you see where expensive (slow) processing is occurring, by adding `Benchmark.realtime` to every `require` / `load`, and printing the result for every file.\n\nAs of version 1.0.4 it can also add timeout, rescue, and additional logging to both `require` and `load`.\n\nThis is an extraction of a debugging tool that I have copy/pasted into many projects over the years, and it is now time to set it free.\n\n*Note*: This gem will make code load slower than normal, but may end up saving you time by showing you where a problem is.\n\n*Warning*: This gem is for debugging problems.  It uses a global **$** variable, which is sad practice.  It uses it as a safety semaphore, so I consider it justified.  If you can think of a better way to implement the safety semaphore, let me know!\n\n*Caveat*: This gem has no effects unless a particular environment variable is set.  It does nothing at all unless it is 'invoked' by detection of the environment variable (`ENV['REQUIRE_BENCH'] == 'true'`).  The *Warning* above is mitigated by the gem not having any of its code, other than the namespace and version, activated under normal circumstances.\n\n| Project                | RequireBench                                                                                                                                                                                                                                                                                                                      |\n|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| gem name               | [require_bench](https://rubygems.org/gems/require_bench)                                                                                                                                                                                                                                                                          |\n| license                | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)                                                                                                                                                                                                                        |\n| download rank          | [![Downloads Today](https://img.shields.io/gem/rd/require_bench.svg)](https://github.com/pboling/require_bench)                                                                                                                                                                                                                   |\n| version                | [![Version](https://img.shields.io/gem/v/require_bench.svg)](https://rubygems.org/gems/require_bench)                                                                                                                                                                                                                             |\n| dependencies           | [![Depfu](https://badges.depfu.com/badges/247bffc753b0cd49d3c08ce03b5c251c/count.svg)](https://depfu.com/github/pboling/require_bench?project_id=5824)                                                                                                                                                                            |\n| continuous integration | [![Current][🚎ini-cwfi]][🚎ini-cwf] [![Heads][🖐ini-hwfi]][🖐ini-hwf] [![Style][🧮ini-swfi]][🧮ini-swf]                                                                                                                                                                                                                           |\n| test coverage          | [![Coverage][📗ini-covwfi]][📗ini-covwf] [![Test Coverage](https://api.codeclimate.com/v1/badges/18523205c207a2b53045/test_coverage)](https://codeclimate.com/github/pboling/require_bench/test_coverage)                                                                                                                         |\n| maintainability        | [![Maintainability](https://api.codeclimate.com/v1/badges/18523205c207a2b53045/maintainability)](https://codeclimate.com/github/pboling/require_bench/maintainability)                                                                                                                                                            |\n| code triage            | [![Open Source Helpers](https://www.codetriage.com/pboling/require_bench/badges/users.svg)](https://www.codetriage.com/pboling/require_bench)                                                                                                                                                                                     |\n| homepage               | [on Github.com][homepage], [on Railsbling.com][blogpage]                                                                                                                                                                                                                                                                          |\n| documentation          | [on RDoc.info][documentation]                                                                                                                                                                                                                                                                                                     |\n| Support                | [Chat on Element / Matrix / Gitter][🏘chat]                                                                                                                                                                                                                                                                                       |\n| Spread ~♡ⓛⓞⓥⓔ♡~        | [🌏](https://about.me/peter.boling), [👼](https://angel.co/peter-boling), [![Liberapay Patrons][⛳liberapay-img]][⛳liberapay] [![Follow Me on LinkedIn][🖇linkedin-img]][🖇linkedin] [![Find Me on WellFound:][✌️wellfound-img]][✌️wellfound] [![My Blog][🚎blog-img]][🚎blog] [![Follow Me on Twitter][🐦twitter-img]][🐦twitter] |\n\n[![Support my refugee and open source work @ ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O86SNP4)\n\n[⛳liberapay-img]: https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay\n[⛳liberapay]: https://liberapay.com/pboling/donate\n[🖇linkedin]: http://www.linkedin.com/in/peterboling\n[🖇linkedin-img]: https://img.shields.io/badge/PeterBoling-blue?style=plastic\u0026logo=linkedin\n[✌️wellfound]: https://angel.co/u/peter-boling\n[✌️wellfound-img]: https://img.shields.io/badge/peter--boling-orange?style=plastic\u0026logo=angellist\n[🐦twitter]: http://twitter.com/intent/user?screen_name=galtzo\n[🐦twitter-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social\u0026label=Follow%20@galtzo\n[🚎blog]: http://www.railsbling.com/tags/oauth2/\n[🚎blog-img]: https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat\n[my🧪lab]: https://gitlab.com/pboling\n[my🧊berg]: https://codeberg.org/pboling\n[my🛖hut]: https://sr.ht/~galtzo/\n\n\u003c!-- columnar badge #s for Project Health table:\n⛳️\n🖇\n🏘\n🚎\n🖐\n🧮\n📗\n🚀\n💄\n👽\n--\u003e\n\n[🚎ini-cwf]: https://github.com/pboling/require_bench/actions/workflows/current.yml\n[🚎ini-cwfi]: https://github.com/pboling/require_bench/actions/workflows/current.yml/badge.svg\n[🖐ini-hwf]: https://github.com/pboling/require_bench/actions/workflows/heads.yml\n[🖐ini-hwfi]: https://github.com/pboling/require_bench/actions/workflows/heads.yml/badge.svg\n[🧮ini-swf]: https://github.com/pboling/require_bench/actions/workflows/style.yml\n[🧮ini-swfi]: https://github.com/pboling/require_bench/actions/workflows/style.yml/badge.svg\n[📗ini-covwf]: https://github.com/pboling/require_bench/actions/workflows/coverage.yml\n[📗ini-covwfi]: https://github.com/pboling/require_bench/actions/workflows/coverage.yml/badge.svg\n\n[🏘chat]: https://matrix.to/#/#pboling_require_bench:gitter.im\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"require_bench\"\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install require_bench\n\n## Usage\n\nRequire the library where it will be loaded prior to any other requires you want to benchmark.\n\n```ruby\nrequire \"require_bench\"\n```\n\nBy default this gem does **nothing**, hacks **nothing**, and has **zero** effects.\n\n### Turn on benchmarking \u0026 output\n\nAdd an environment variable, however you normally do such things, so that in Ruby:\n\n```ruby\nENV[\"REQUIRE_BENCH\"] == \"true\"\n```\n\nAny value other than `'true'` means RequireBench is still turned off.\n\n### Handy Rake Task\n\n#### For a Gem Library\n\nRequire in Rakefile:\n\n```ruby\nrequire \"bundler/setup\"\nrequire \"require_bench/tasks\" # Near the top, just below require 'bundler/setup'!\n```\n\n#### For Rails\n\nRequire in Rakefile:\n\n```ruby\nrequire_relative \"config/application\"\nrequire \"require_bench/tasks\" if ENV[\"REQUIRE_BENCH\"] == \"true\" # Near the top, just below require_relative 'config/application'!\n```\n\n#### Example\n\nWhen running from command line, you will see output as the Rails app boots. In the case below it ignores all gem libraries, and only tracks Rails.\nThe output at the top shows the config being used.\n```bash\n$ REQUIRE_BENCH=true bundle exec rake require_bench:hello\n[RequireBench] Using skip pattern: (?-mix:gems)\n[RequireBench] Using include pattern: (?-mix:my_app)\n[RequireBench] Using no group pattern: (?-mix:ext|config)\n🚥 [RequireBench-r] ☑️   0.005564 /Volumes/🐉🩸/src/apps/my_app/lib/middleware/omniauth_bypass.rb 🚥\n🚥 [RequireBench-r] ☑️   0.001099 /Volumes/🐉🩸/src/apps/my_app/lib/middleware/sidekiq/match_deployment_rules.rb 🚥\n🚥 [RequireBench-r] ☑️   0.001121 /Volumes/🐉🩸/src/apps/my_app/lib/middleware/sidekiq/request_store.rb 🚥\n🚥 [RequireBench-r] ☑️   0.000989 /Volumes/🐉🩸/src/apps/my_app/lib/middleware/sidekiq/clear_active_record_connections.rb 🚥\n🚥 [RequireBench-r] ☑️   0.006890 /Volumes/🐉🩸/src/apps/my_app/lib/middleware/sidekiq/worker_killer.rb 🚥\n🚥 [RequireBench-r] ☑️   0.001990 /Volumes/🐉🩸/src/apps/my_app/lib/parsers/pku_parser.rb 🚥\n\n[RequireBench] Slowest Loads by Library, in order\n 1.   0.017653 my_app\n==========\n  0.017653 TOTAL\n```\n\n### Output Options\n\nIf the output is too noisy from deep libraries you can add a regex to skip benchmarking of files that match.\n\n```bash\nexport REQUIRE_BENCH_SKIP_PATTERN=activesupport,rspec\n```\n\n`ENV['REQUIRE_BENCH_SKIP_PATTERN']` must be one of:\n  * a string, to be split by comma (`,`), then joined by pipe (`|`) with `Regexp.union`\n  * a string, to be split by pipe (`|`), then joined by pipe (`|`) with `Regexp.union`\n\n```ruby\nENV[\"REQUIRE_BENCH_SKIP_PATTERN\"] = \"activesupport,rspec\"\n# or\nENV[\"REQUIRE_BENCH_SKIP_PATTERN\"] = \"activesupport|rspec\"\n```\n\nAny file being required that matches the pattern will use the standard, rather than the benchmarked, require.\n\n#### Fully qualified paths\n\nFully qualified paths, or any portion thereof, are fine, because the strings are always Regexp escaped.\n\n### Other ENV control variables\n\n- wrap/log load in addition to require\n    - `ENV['REQUIRE_BENCH_TRACKED_METHODS']`\n- rescue errors\n    - `ENV['REQUIRE_BENCH_RESCUED_CLASSES']`\n- log start\n    - `ENV['REQUIRE_BENCH_LOG_START']`\n- load/require timeout\n    - `ENV['REQUIRE_BENCH_TIMEOUT']`\n- A pattern for paths that should be included/tracked\n    - `ENV['REQUIRE_BENCH_INCLUDE_PATTERN']`\n- Should grouping be by basename or by path?\n    - `ENV['REQUIRE_BENCH_GROUP_PRECEDENCE']`\n- Prefer to not group some pattern (i.e. some libraries)\n    - `ENV['REQUIRE_BENCH_NO_GROUP_PATTERN']`\n\nIf you'd like to help document any of these further, PRs are appreciated!\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\nTo get code coverage:\n```shell\nCI_CODECOV=true COVER_ALL=false bundle exec rspec\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/pboling/require_bench.\n\n## Code of Conduct\n\nEveryone interacting in the AnonymousActiveRecord project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pboling/require_bench/blob/master/CODE_OF_CONDUCT.md).\n\n## Versioning\n\nThis library aims to adhere to [Semantic Versioning 2.0.0][semver].\nViolations of this scheme should be reported as bugs. Specifically,\nif a minor or patch version is released that breaks backward\ncompatibility, a new version should be immediately released that\nrestores compatibility. Breaking changes to the public API will\nonly be introduced with new major versions.\n\nAs a result of this policy, you can (and should) specify a\ndependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.\n\nFor example:\n\n```ruby\nspec.add_dependency(\"require_bench\", \"~\u003e 0.0\")\n```\n\n## License\n\n* Copyright (c) 2018-2020, 2023 [Peter H. Boling][peterboling] of [Rails Bling][railsbling]\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\n[license]: LICENSE\n[semver]: http://semver.org/\n[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint\n[railsbling]: http://www.railsbling.com\n[peterboling]: http://www.peterboling.com\n[documentation]: http://rdoc.info/github/pboling/require_bench/frames\n[homepage]: https://github.com/pboling/require_bench/\n[blogpage]: http://www.railsbling.com/tags/require_bench/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpboling%2Frequire_bench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpboling%2Frequire_bench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpboling%2Frequire_bench/lists"}