{"id":30794002,"url":"https://github.com/sendgrid/stopwatch","last_synced_at":"2026-03-17T19:24:42.855Z","repository":{"id":29297498,"uuid":"32830498","full_name":"sendgrid/stopwatch","owner":"sendgrid","description":"Benchmark your Go code  with this utility for keeping track of timing information for different states.","archived":false,"fork":false,"pushed_at":"2019-03-04T08:04:44.000Z","size":25,"stargazers_count":10,"open_issues_count":2,"forks_count":7,"subscribers_count":178,"default_branch":"master","last_synced_at":"2025-09-05T16:46:02.642Z","etag":null,"topics":["coreplatform"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sendgrid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-24T23:12:20.000Z","updated_at":"2025-04-02T07:27:58.000Z","dependencies_parsed_at":"2022-08-30T04:01:37.963Z","dependency_job_id":null,"html_url":"https://github.com/sendgrid/stopwatch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sendgrid/stopwatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fstopwatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fstopwatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fstopwatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fstopwatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sendgrid","download_url":"https://codeload.github.com/sendgrid/stopwatch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendgrid%2Fstopwatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30629211,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"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":["coreplatform"],"created_at":"2025-09-05T16:26:31.362Z","updated_at":"2026-03-17T19:24:42.848Z","avatar_url":"https://github.com/sendgrid.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"stopwatch\n==========\n\nThis package offers a nice solution to take some measurements of the various states of your application.  It is a non high-resolution timer that is designed to be fast giving you an accurate picture of how long your code paths are taking.\n\n[![BuildStatus](https://travis-ci.org/sendgrid/stopwatch.svg?branch=master)](https://travis-ci.org/sendgrid/stopwatch)\n[![Go Report Card](https://goreportcard.com/badge/github.com/sendgrid/stopwatch)](https://goreportcard.com/report/github.com/sendgrid/stopwatch)\n[![GoDoc](https://godoc.org/github.com/sendgrid/stopwatch?status.svg)](https://godoc.org/github.com/sendgrid/stopwatch)\n\n### Usage\n\n```Go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"github.com/sendgrid/stopwatch\"\n\t\"time\"\n)\n\nfunc main() {\n\n\t// Create a new StopWatch that starts off counting\n\tsw := stopwatch.New(0, true)\n\n\t// Optionally, format that time.Duration how you need it\n\t// sw.SetFormatter(func(duration time.Duration) string {\n\t// \treturn fmt.Sprintf(\"%.3f\", (duration.Seconds()*1000.0)/1000.0)\n\t// })\n\n\t// Take measurement of various states\n\tsw.Lap(\"Create File\")\n\n\t// Simulate some time by sleeping\n\ttime.Sleep(time.Millisecond * 300)\n\tsw.Lap(\"Edit File\")\n\n\ttime.Sleep(time.Second * 2)\n\tsw.Lap(\"Save File\")\n\n\ttime.Sleep(time.Second * 3)\n\tsw.Lap(\"Upload File\")\n\n\t// Take a measurement with some additional metadata\n\ttime.Sleep(time.Millisecond * 20)\n\tsw.LapWithData(\"Delete File\", map[string]interface{}{\n\t\t\"filename\": \"word.doc\",\n\t\t\"size\":     \"1024\",\n\t})\n\n\t// Stop the timer\n\tsw.Stop()\n\n\t// Marshal to json\n\tif b, err := json.Marshal(sw); err == nil {\n\t\tfmt.Println(string(b))\n\t}\n}\n```\n\nYou can also use stopwatch inside different goroutines like so,\n```Go\n\t// Create a new StopWatch that starts off counting\n\tsw := New(0, true)\n\n\t// Optionally, format that time.Duration how you need it\n\tsw.SetFormatter(func(duration time.Duration) string {\n\t\treturn fmt.Sprintf(\"%.1f\", duration.Seconds())\n\t})\n\n\t// Take measurement of various states\n\tsw.Lap(\"Create File\")\n\n\tvar wg sync.WaitGroup\n\n\twg.Add(2)\n\tgo func() {\n\t\tdefer wg.Done()\n\t\tfor i := 0; i \u003c 2; i++ {\n\t\t\ttime.Sleep(time.Millisecond * 200)\n\t\t\ttask := fmt.Sprintf(\"task %d\", i)\n\t\t\tsw.Lap(task)\n\t\t}\n\t}()\n\n\tgo func() {\n\t\tdefer wg.Done()\n\t\ttime.Sleep(time.Second * 1)\n\t\ttask := \"task A\"\n\t\tsw.LapWithData(task, map[string]interface{}{\n\t\t\t\"filename\": \"word.doc\",\n\t\t})\n\t}()\n\n\t// Simulate some time by sleeping\n\ttime.Sleep(time.Second * 1)\n\tsw.Lap(\"Upload File\")\n\n\t// Stop the timer\n\twg.Wait()\n\tsw.Stop()\n\n\t// Marshal to json\n\tif b, err := json.Marshal(sw); err == nil {\n\t\tfmt.Println(string(b))\n\t}\n\n\t// Output:\n\t// [{\"state\":\"Create File\",\"time\":\"0.0\"},{\"state\":\"task 0\",\"time\":\"0.2\"},{\"state\":\"task 1\",\"time\":\"0.2\"},{\"state\":\"Upload File\",\"time\":\"0.6\"},{\"state\":\"task A\",\"time\":\"0.0\",\"filename\":\"word.doc\"}]\n\n```\n\n### Sample Output in Json format\n\n```json\n[\n    {\n        \"state\": \"Create File\",\n        \"time\": \"1.341\"\n    },\n    {\n        \"state\": \"Edit File\",\n        \"time\": \"300.48635\"\n    },\n    {\n        \"state\": \"Save File\",\n        \"time\": \"2.001098212\"\n    },\n    {\n        \"state\": \"Upload File\",\n        \"time\": \"3.000983896\"\n    },\n    {\n        \"state\": \"Delete File\",\n        \"time\": \"20.724059\",\n        \"filename\": \"word.doc\",\n        \"size\": \"1024\"\n    }\n]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsendgrid%2Fstopwatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsendgrid%2Fstopwatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsendgrid%2Fstopwatch/lists"}