{"id":13880298,"url":"https://github.com/copiousfreetime/hitimes","last_synced_at":"2025-07-16T16:31:29.594Z","repository":{"id":431916,"uuid":"52462","full_name":"copiousfreetime/hitimes","owner":"copiousfreetime","description":"a fast, high resolution timer library for recording performance metrics","archived":false,"fork":false,"pushed_at":"2025-05-08T15:19:08.000Z","size":464,"stargazers_count":148,"open_issues_count":1,"forks_count":17,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-07-05T16:11:29.816Z","etag":null,"topics":["metrics","ruby","stats"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/copiousfreetime.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":"CONTRIBUTING.md","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}},"created_at":"2008-09-14T06:52:43.000Z","updated_at":"2025-03-04T16:20:09.000Z","dependencies_parsed_at":"2024-05-01T06:23:19.973Z","dependency_job_id":"ed1f5fa3-44d5-4776-b308-58067e707ed1","html_url":"https://github.com/copiousfreetime/hitimes","commit_stats":{"total_commits":394,"total_committers":11,"mean_commits":35.81818181818182,"dds":"0.48477157360406087","last_synced_commit":"55e0ba8b34f43927fe43f27b709e4863fdbaacbc"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/copiousfreetime/hitimes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copiousfreetime%2Fhitimes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copiousfreetime%2Fhitimes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copiousfreetime%2Fhitimes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copiousfreetime%2Fhitimes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/copiousfreetime","download_url":"https://codeload.github.com/copiousfreetime/hitimes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copiousfreetime%2Fhitimes/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264467185,"owners_count":23612865,"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":["metrics","ruby","stats"],"created_at":"2024-08-06T08:02:55.583Z","updated_at":"2025-07-16T16:31:29.561Z","avatar_url":"https://github.com/copiousfreetime.png","language":"Ruby","readme":"# Hitimes\n[![Build Status](https://copiousfreetime.semaphoreci.com/badges/hitimes/branches/main.svg)](https://copiousfreetime.semaphoreci.com/projects/hitimes)\n\n* [Homepage](http://github.com/copiousfreetime/hitimes)\n* [Github project](http://github.com/copiousfreetime/hitimes)\n\n## DESCRIPTION\n\nA fast, high resolution timer library for recording performance metrics.\n\n## TABLE OF CONTENTS\n\n* [Requirements](#requirements)\n* [Usage](#usage)\n* [Contributing](#contributing)\n* [Support](#support)\n* [License](#license)\n\n\n## REQUIREMENTS\n\nHitimes requires the following to run:\n\n  * Ruby\n\n## USAGE\n\nHitimes easiest to use when installed with `rubygems`:\n\n```sh\ngem install hitimes\n```\n\nOr as part of your bundler `Gemfile`:\n\n```ruby\ngem \"hitimes\"\n```\n\nYou can load it with the standard ruby require statement.\n\n```ruby\nrequire \"hitimes\"\n```\n\n### Interval\n\nUse `Hitimes::Interval` to calculate only the duration of a block of code.\nReturns the time as seconds.\n\n```ruby\nduration = Hitimes::Interval.measure do\n  1_000_000.times do |x|\n    2 + 2\n  end\nend\n\nputs duration  # =\u003e 0.047414297 (seconds)\n```\n\n### TimedMetric\n\nUse a `Hitimes::TimedMetric` to calculate statistics about an iterative operation\n\n```ruby\ntimed_metric = Hitimes::TimedMetric.new(\"operation on items\")\n```\n\nExplicitly use `start` and `stop`:\n\n```ruby\ncollection.each do |item|\n  timed_metric.start\n  # .. do something with item\n  timed_metric.stop\nend\n```\n\nOr use the block. In `TimedMetric` the return value of `measure` is the return\nvalue of the block.\n\n```ruby\ncollection.each do |item|\n  result_of_do_something = timed_metric.measure { do_something(item) }\n  # do something with result_of_do_something\nend\n```\nAnd then look at the stats\n\n```ruby\nputs timed_metric.mean\nputs timed_metric.max\nputs timed_metric.min\nputs timed_metric.stddev\nputs timed_metric.rate\n```\n\n### ValueMetric\n\nUse a `Hitimes::ValueMetric` to calculate statistics about measured samples.\n\n``` ruby\nvalue_metric = Hitimes::ValueMetric.new(\"size of thing\")\nloop do\n  # ... do stuff changing sizes of 'thing'\n  value_metric.measure(thing.size)\n  # ... do other stuff that may change size of thing\nend\n\nputs value_metric.mean\nputs value_metric.max\nputs value_metric.min\nputs value_metric.stddev\nputs value_metric.rate\n```\n\n### TimedValueMetric\n\nUse a `Hitimes::TimedValueMetric` to calculate statistics about batches of samples.\n\n``` ruby\ntimed_value_metric = Hitimes::TimedValueMetric.new(\"batch times\")\nloop do\n  batch = ... # get a batch of things\n  timed_value_metric.start\n  # .. do something with batch\n  timed_value_metric.stop(batch.size)\nend\n\nputs timed_value_metric.rate\n\nputs timed_value_metric.timed_stats.mean\nputs timed_value_metric.timed_stats.max\nputs timed_value_metric.timed_stats.min\nputs timed_value_metric.timed_stats.stddev\n\nputs timed_value_metric.value_stats.mean\nputs timed_value_metric.value_stats.max\nputs timed_value_metric.value_stats.min\nputs timed_value_metric.value_stats.stddev\n```\n\n### Implementation details\n\nHitimes uses the internal ruby `Process::clock_gettime()` to\nget the highest granularity time increment possible. Generally this is\nnanosecond resolution, or whatever the hardware in the CPU supports.\n\n## SUPPORT\n\nHitimes is supported on whatever versions of ruby are currently supported.\nHitimes also follows [semantic versioning](http://semver.org/).\n\nThe current officially supported versions of Ruby are:\n\n* MRI Ruby (all platforms) 3.0 - current\n* JRuby 9.4.x.x\n* Truffleruby 24\n\nUnofficially supported versions, any version of MRI from Ruby 2.1 and up. Since\nthe C Extension has been removed Hitimes should work with any ruby that is 2.1\nor greater as that is when `Process.clock_gettime()` was implemented.\n\nFor versions of Ruby before 2.1 please use Hitimes 1.3, the extension code is\nstill in there and they should still work.\n\n## CONTRIBUTING\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on development\nand bug reporting.\n\n## Credits\n\n* [Bruce Williams](https://github.com/bruce) for suggesting the idea.\n* [Benoit Daloze](https://github.com/eregon) and [Thomas Hurst](https://github.com/Freaky) for conversations around clock_ids.\n\n## License\n\nHitimes is licensed under the [ISC](https://opensource.org/licenses/ISC)\nlicense.\n\n## Related Works\n\n* [monotime](https://github.com/Freaky/monotime) - A sensible interface to Ruby's monotonic clock.\n* [concurrent-ruby](https://github.com/ruby-concurrency/concurrent-ruby) - [Concurrent.monotonic_time](https://github.com/ruby-concurrency/concurrent-ruby) is a straight pass through to `Process.clock_gettime(Process::CLOCK_MONOTONIC,...)`.\n* [Instant](https://doc.rust-lang.org/src/std/time.rs.html) - The rust equivalent.\n* [time.Now](https://pkg.go.dev/time) - The go monotonic time interface is part of this package.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcopiousfreetime%2Fhitimes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcopiousfreetime%2Fhitimes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcopiousfreetime%2Fhitimes/lists"}