{"id":30873479,"url":"https://github.com/omgreenfield/class-profiler","last_synced_at":"2026-01-20T17:00:53.063Z","repository":{"id":312486078,"uuid":"1047159234","full_name":"omgreenfield/class-profiler","owner":"omgreenfield","description":"A gem to easily track performance and memory usage of a class's methods","archived":false,"fork":false,"pushed_at":"2025-09-04T05:45:20.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-07T14:32:57.029Z","etag":null,"topics":["benchmark","gem","memory","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/omgreenfield.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-29T20:54:01.000Z","updated_at":"2025-09-04T05:48:04.000Z","dependencies_parsed_at":"2025-08-31T01:19:31.760Z","dependency_job_id":null,"html_url":"https://github.com/omgreenfield/class-profiler","commit_stats":null,"previous_names":["omgreenfield/class-profiler"],"tags_count":0,"template":false,"template_full_name":"omgreenfield/ruby-gem-template","purl":"pkg:github/omgreenfield/class-profiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omgreenfield%2Fclass-profiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omgreenfield%2Fclass-profiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omgreenfield%2Fclass-profiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omgreenfield%2Fclass-profiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omgreenfield","download_url":"https://codeload.github.com/omgreenfield/class-profiler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omgreenfield%2Fclass-profiler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","gem","memory","ruby"],"created_at":"2025-09-07T23:11:05.193Z","updated_at":"2026-01-20T17:00:52.684Z","avatar_url":"https://github.com/omgreenfield.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"ClassProfiler: track performance and memory allocations in Ruby classes\n\n### Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'class-profiler'\n```\n\nAnd then execute:\n\n```bash\nbundle install\n```\n\nOr install it yourself as:\n\n```bash\ngem install class-profiler\n```\n\n### Usage\n\nInclude `ClassProfiler` in your class. Use the unified class-level helpers to wrap methods.\n\n```ruby\nclass Report\n  include ClassProfiler\n\n  def fetch\n    sleep 0.01\n    'ok'\n  end\n\n  def allocate\n    Array.new(1000) { 'x' * 10 }\n  end\n\n  # Track non-inherited public/protected/private instance methods (default)\n  track_performance\n  track_memory\nend\n\nr = Report.new\nr.fetch\nr.allocate\n\n# Per-method metrics\nr.performance        # =\u003e { fetch: { time: 0.0102, total: 0.0306 } }\nr.memory             # =\u003e { allocate: { allocated_objects: 1005, malloc_increase_bytes: 8192 } }\n\n# Combined view (performance + memory)\nr.profile            # =\u003e { fetch: { time: 0.0102 }, allocate: { objects: 1005, bytes: 8192 } }\n\n# Reports\nr.performance_report # prints a table of last time and total time\nr.memory_report      # prints a table of allocations/bytes\nr.profile_report     # prints a combined table\n```\n\nSelection is controlled via flags on the unified helpers:\n\n```ruby\n# Include inherited methods?\ntrack_performance inherited: true\ntrack_memory inherited: true\n\n# Choose visibilities (public/protected/private default to true)\ntrack_performance protected: false, private: false\ntrack_memory public: true, protected: false, private: false\n```\n\n### API\n\n- `track_performance(inherited: false, public: true, protected: true, private: true)`\n- `track_memory(inherited: false, public: true, protected: true, private: true)`\n- `performance` (instance): Hash of method name → `{ time: Float, total: Float }`\n- `memory` (instance): Hash of method name → allocation deltas\n  - `allocated_objects` (Integer)\n  - `malloc_increase_bytes` (Integer)\n- `profile` (instance): Combined Hash of method name → `{ time:, objects:, bytes: }`\n- `performance_report`, `memory_report`, `profile_report` (instance): print tabular reports\n\n### Composing with wrap_method\n\nYou can compose custom behaviors using the built-in `wrap_method` helper from `ClassProfiler::Methods`.\nThis is the same mechanism used by the Performance and Memory modules under the hood.\n\n```ruby\nclass Widget\n  include ClassProfiler\n\n  def compute(x, y)\n    x + y\n  end\n\n  # Add custom logging around the original implementation\n  wrap_method :compute do |original, *args|\n    profiler_logger.info(\"compute called with #{args.inspect}\")\n    result = original.bind(self).call(*args)\n    profiler_logger.info(\"compute returned #{result}\")\n    result\n  end\n\n  # You can still benchmark or profile the same method\n  track_performance\n  # track_memory\nend\n\nw = Widget.new\nw.compute(2, 3)\nw.performance[:compute] # =\u003e { time:, total: }\n```\n\n### Requirements\n\n- Ruby \u003e= 3.1\n\n### Development\n\n- Run `bin/setup` to install dependencies\n- Run `rake` to execute tests and RuboCop\n- Run `bin/console` to experiment in Pry\n\n### Examples (speed vs memory trade-offs)\n\nExplore the gem with runnable examples that contrast time vs memory usage for common problems.\n\nRun all examples:\n\n```bash\nbundle exec rake examples\n```\n\nWhat you'll see:\n\n```text\n=== Two Sum: brute_force (low memory, slower) vs hashmap (higher memory, faster) ===\nInput SIZE=5000\n\nSummary (lower time is better; lower allocations usually better):\nMethod           Time (s)     Allocated Objects     Malloc +bytes\n----------------------------------------------------------------------\nbrute_force      0.456789     12345                 0\nhashmap          0.012345     45678                 8192\n\nSpeed: hashmap is 37.00x faster than brute_force\nMemory: hashmap allocates 3.70x more objects than brute_force\n\nRaw reports:\n...\n```\n\nYou can run individual examples and tune sizes:\n\n```bash\n# Two Sum: brute force vs hash map\nSIZE=10000 bundle exec ruby examples/two_sum.rb\n\n# Primes: trial division vs sieve of Eratosthenes\nN=50000 bundle exec ruby examples/primes.rb\n```\n\nEach example prints a concise table plus a human-readable conclusion highlighting the trade-off (e.g. \"sieve is 10x faster but allocates 4x more objects\").\n\n### Contributing\n\nBug reports and pull requests are welcome on GitHub at `https://github.com/omgreenfield/class-profiler`.\n\n### License\n\nThe gem is available as open source under the terms of the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomgreenfield%2Fclass-profiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomgreenfield%2Fclass-profiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomgreenfield%2Fclass-profiler/lists"}