{"id":17041665,"url":"https://github.com/xlab/pace","last_synced_at":"2025-04-12T14:33:39.502Z","repository":{"id":57491308,"uuid":"78841140","full_name":"xlab/pace","owner":"xlab","description":"Package pace provides a threadsafe counter for measuring ticks in the specified timeframe.","archived":false,"fork":false,"pushed_at":"2023-08-17T14:14:30.000Z","size":8,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-26T11:18:34.652Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/xlab.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}},"created_at":"2017-01-13T10:50:13.000Z","updated_at":"2023-08-17T14:14:35.000Z","dependencies_parsed_at":"2024-06-20T02:49:11.979Z","dependency_job_id":"caff0ed8-ee48-4cd6-9534-44fc012bb07f","html_url":"https://github.com/xlab/pace","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlab%2Fpace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlab%2Fpace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlab%2Fpace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlab%2Fpace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xlab","download_url":"https://codeload.github.com/xlab/pace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219847462,"owners_count":16556351,"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":[],"created_at":"2024-10-14T09:13:08.405Z","updated_at":"2024-10-14T09:13:08.961Z","avatar_url":"https://github.com/xlab.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Pace [![GoDoc](https://godoc.org/github.com/xlab/pace?status.svg)](https://godoc.org/github.com/xlab/pace) [![Go Report Card](http://goreportcard.com/badge/github.com/xlab/pace)](http://goreportcard.com/report/github.com/xlab/pace)\n\nPace is a Go package that helps to answer one simple question:\n\n\u003e how fast it goes?\n\n![pace](https://cl.ly/2P163D3Q0O03/pace.gif)\n\nIt's a threadsafe counter that measures ticks in the specified timeframe. It also has a simple and intuitive interface:\n\n```go\nfunc New(label string, interval time.Duration, repFn ReporterFunc) Pace\n\ntype Pace interface {\n    // Step increments the counter of pace.\n    Step(n float64)\n    // Pause stops reporting until resumed, all steps continue to be counted.\n    Pause()\n    // Resume resumes the reporting, immediately reports info since the last tick.\n    // Specify a new interval or 0 if you don't want to override it.\n    Resume(interval time.Duration)\n    // Report manually triggers a report with time frame less than the defined interval.\n    // Specify a custom reporter function just for this one report.\n    Report(reporter ReporterFunc)\n}\n\n// ReporterFunc defines a function used to report current pace.\ntype ReporterFunc func(label string, timeframe time.Duration, value float64)\n```\n\n### Installation\n\n```\n$ go get github.com/xlab/pace\n```\n\n### Usage example:\n\n```go\n\n// initialise a pace meter\np := New(\"items\", time.Second, nil)\ngo func() {\n    for range items {\n        wg.Done()\n        p.Step(1)\n    }\n}()\n\n// start pushing items:\n\n// pushing each 1ms\npush(1*time.Millisecond, 3*time.Second)\n// pushing each 10ms\npush(10*time.Millisecond, 3*time.Second)\n// pushing each 100ms\npush(100*time.Millisecond, 3*time.Second)\n// pushing each 500ms\npush(500*time.Millisecond, 3*time.Second)\n```\n\nFull code available at [pace_test.go](/pace_test.go).\n\n#### Output:\n\n```\n$ go test\n2017/01/13 13:29:51 items: 999/s in 1s\n2017/01/13 13:29:52 items: 1001/s in 1s\n2017/01/13 13:29:53 items: 1000/s in 1s\n2017/01/13 13:29:54 items: 100/s in 1s\n2017/01/13 13:29:55 items: 100/s in 1s\n2017/01/13 13:29:56 items: 100/s in 1s\n2017/01/13 13:29:57 items: 10/s in 1s\n2017/01/13 13:29:58 items: 10/s in 1s\n2017/01/13 13:29:59 items: 10/s in 1s\n2017/01/13 13:30:00 items: 2/s in 1s\n2017/01/13 13:30:01 items: 2/s in 1s\n2017/01/13 13:30:02 items: 2/s in 1s\n2017/01/13 13:30:02 done\nPASS\nok      github.com/xlab/pace    12.006s\n```\n\nAlso within **5 second** timeframe using `pace.New(\"items\", 5 * time.Second, nil)`\n\n```\n$ go test\n2017/01/13 13:32:06 3199 items in 5s (pace: 3199/s)\n2017/01/13 13:32:11 133 items in 5s (pace: 133/s)\n2017/01/13 13:32:13 4 items in 1.999796727s (pace: 4/s)\n2017/01/13 13:32:13 done\nPASS\nok      github.com/xlab/pace    12.006s\n```\n\n### License\n\n[MIT](/LICENSE.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlab%2Fpace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxlab%2Fpace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlab%2Fpace/lists"}