{"id":13665336,"url":"https://github.com/ringabout/timeit","last_synced_at":"2026-01-12T01:55:23.395Z","repository":{"id":49979392,"uuid":"213543334","full_name":"ringabout/timeit","owner":"ringabout","description":"measuring execution times written by Nim.","archived":false,"fork":false,"pushed_at":"2022-11-06T12:05:48.000Z","size":42,"stargazers_count":37,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-14T21:04:15.565Z","etag":null,"topics":["bench","nim","nimble","timeit"],"latest_commit_sha":null,"homepage":"","language":"Nim","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/ringabout.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-08T03:44:09.000Z","updated_at":"2025-07-06T18:18:29.000Z","dependencies_parsed_at":"2023-01-22T02:35:18.500Z","dependency_job_id":null,"html_url":"https://github.com/ringabout/timeit","commit_stats":null,"previous_names":["xflywind/timeit"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/ringabout/timeit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringabout%2Ftimeit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringabout%2Ftimeit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringabout%2Ftimeit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringabout%2Ftimeit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ringabout","download_url":"https://codeload.github.com/ringabout/timeit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringabout%2Ftimeit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28331315,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"ssl_error","status_checked_at":"2026-01-12T00:36:15.229Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["bench","nim","nimble","timeit"],"created_at":"2024-08-02T06:00:32.966Z","updated_at":"2026-01-12T01:55:23.380Z","avatar_url":"https://github.com/ringabout.png","language":"Nim","funding_links":[],"categories":["性能测试"],"sub_categories":[],"readme":"# timeit [![nimble](https://raw.githubusercontent.com/yglukhov/nimble-tag/master/nimble.png)](https://github.com/yglukhov/nimble-tag)\nmeasuring execution times written in nim.\n\n## Installation\n```text\nnimble install timeit\n```\n## Documention\nhttps://xflywind.github.io/timeit/src/main.html\n\n## Usage\n### import timeit\nIn **timeit** module, you can use the **timeGo** to\nmeasure execution times of proc. \\\nThere are three parameters in **timeGo**.\\\n**myFunc** is the call of proc. **repeatTimes** is\nhow many times you want to measure, the result is the average of all the times, **loopTimes** is how many loops you want to execute in each time.\nIf you don't give the value of **loopTimes**, the program will calculate the **loopTimes** according to the execution times in first time.    \n```nim\ntemplate timeGo*(myFunc: untyped, \n                repeatTimes: int = repeatTimes, \n                loopTimes: int = loopTimes): Timer\n```\nWhen you want to pass **myFunc** parameter to **timeGo**, there are some points you should take care of. \\\nIf you want to pass the proc without return value, you should use the call of the proc, namely **myProc(args)**. \\\nIf you want to pass the proc with return value,\nyou should add the pragma **{.discardable.}** to the\ndefinitions of your proc.Then you can use **timeGo**\nto measure the execution times of your proc, namely **myProc(args)**.\n\n### another Way\nYou can also use timeGo as follow:\n```nim\nimport os\n\necho timeGo do:\n  os.sleep(12)\n  var a = 12\n  for i in 1 .. 1000:\n  a += 12\n# output [12ms 883μs 34.58ns] ± [19μs 974.83ns] per loop (mean ± std. dev. of 7 runs, 10 loops each)\n```\nor you can specify the repeatTimes and loopTimes as follows:\n```nim\ntimeGo(1, 1):\n  var b = 12\n  b += 12\n# output [200.00ns] ± [0.00ns] per loop (mean ± std. dev. of 1 runs, 1 loops each)\n```\n### use monit function\nYou can use monit function to measure the times\nof code executions. \\\nFirst you can specify the **name** of this test,\nfor example, \"first\".Then you can place the\n**start** function in the begin of the code you want\nto measure, and place the **finsih** function in the\nend of the code you want to measure.\n```nim\nimport timeit\nvar m = monit(\"first\")\nm.start()\nlet a = 12\necho a + 3 \nm.finish()\n# first -\u003e [17μs 0.00ns]\n```\nYou can also monit once as follows:\n```nim\ntimeOnce(\"test-once\"):\n  var a = 12\n  for i in 1 .. 10000:\n    a += i\n  echo a\n```\n\n\n### use command-line interface\nFirstly, you need to make sure that your **.nimble** directory must be in your path environment.\nThen you can use **timeit --name=yourNimFile --def=yourProc**. \\\nHowever, string parameters can't appear in yourProc.And If you want\nto specify more than one parameter, you should use **\"yourProc(parameters)\"**.\n\n```nim\n# in bash\ntimeit --name=test --def=hello()\n# [46ms 290μs 893.17ns] ± [1ms 164μs 333.97ns] per loop (mean ± std. dev. of 7 runs, 10 loops each)\n```\nYou can also measure the execution time of the whole Nim file.\n```nim\n# in bash\ntimeit test.nim\n# debug mode\n# test-whole -\u003e [208μs 100.00ns]\n\n# or specify the -d flag\ntimeit test.nim -d:release\n# release mode\n# test-whole -\u003e [29μs 200.00ns]\n```\n\n\n\n## Examples\nfor proc without return value\n```nim\nimport timeit\n\nproc mySleep(num: varargs[int]) = \n  for i in 1 .. 10:\n    discard\necho timeGo(mySleep(5, 2, 1))\n# [216.50ns] ± [1μs 354.44ns] per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n```\nfor proc with return value\n```nim\nimport timeit\n\nproc mySleep(num: varargs[int]): int {.discardable.} = \n  for i in 1 .. 10:\n    discard\necho timeGo(mySleep(5, 2, 1)) \n# [221.82ns] ± [1μs 837.93ns] per loop (mean ± std. dev. of 7 runs, 1000000 loops each) \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringabout%2Ftimeit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fringabout%2Ftimeit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringabout%2Ftimeit/lists"}