{"id":20048613,"url":"https://github.com/sbwerewolf/stopwatch","last_synced_at":"2025-09-11T23:18:00.033Z","repository":{"id":65730562,"uuid":"598364309","full_name":"SbWereWolf/stopwatch","owner":"SbWereWolf","description":"Primitive stopwatch with simple start and stop for measurement of periods and whole time","archived":false,"fork":false,"pushed_at":"2023-02-10T23:48:36.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-29T23:17:55.601Z","etag":null,"topics":["duration","hrtime","microtime","php-library","stopwatch"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/SbWereWolf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-02-07T00:24:30.000Z","updated_at":"2023-02-09T11:35:16.000Z","dependencies_parsed_at":"2023-04-20T09:59:13.394Z","dependency_job_id":null,"html_url":"https://github.com/SbWereWolf/stopwatch","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/SbWereWolf/stopwatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SbWereWolf%2Fstopwatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SbWereWolf%2Fstopwatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SbWereWolf%2Fstopwatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SbWereWolf%2Fstopwatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SbWereWolf","download_url":"https://codeload.github.com/SbWereWolf/stopwatch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SbWereWolf%2Fstopwatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274726354,"owners_count":25338393,"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","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["duration","hrtime","microtime","php-library","stopwatch"],"created_at":"2024-11-13T11:44:48.199Z","updated_at":"2025-09-11T23:18:00.028Z","avatar_url":"https://github.com/SbWereWolf.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple stopwatch\n\nPrimitive stopwatch, with simple start and stop methods,\nfor measurement of every single time periods and all time whole.\n\n## How to install\n\n`composer require sbwerewolf/stopwatch`\n\n## How to use\n\n```php\necho 'Duration is ' .\n    (new \\SbWereWolf\\Stopwatch\\HRTimeStopwatch())\n    -\u003estart()-\u003estop()-\u003egetLastTime()-\u003easNanoSeconds() .\n    ' ns' .\n    PHP_EOL;\n```\n\n```bash\nDuration is 300 ns\n```\n\nStopwatch available with different engines:\n\n- `hrtime()`\n- `microtime()`\n- `DateTimeImmutable`\n\n`\\SbWereWolf\\Stopwatch\\HRTimeStopwatch` implements\n`hrtime()` engine.\n\n`\\SbWereWolf\\Stopwatch\\MicroTimeStopwatch` implements\n`microtime()` engine.\n\n`\\SbWereWolf\\Stopwatch\\DateTimeStopwatch` implements\n`DateTimeImmutable` engine.\n\n## Advanced usage\n\n```php\n$stopwatch = new SbWereWolf\\Stopwatch\\HRTimeStopwatch();\necho (new DateTimeImmutable())-\u003eformat('s.u') . PHP_EOL;\n\n$stopwatch-\u003estart();\ntime_nanosleep(0, 100);\n$stopwatch-\u003estop();\n\necho (new DateTimeImmutable())-\u003eformat('s.u') .\n    ' Period 1 duration: ' .\n    $stopwatch-\u003egetLastTime()-\u003easNanoSeconds() .\n    ' ns' .\n    PHP_EOL;\n\ntime_nanosleep(0, 100);\n\n$stopwatch-\u003estart();\ntime_nanosleep(0, 100);\n$stopwatch-\u003estop();\n\necho (new DateTimeImmutable())-\u003eformat('s.u') .\n    ' Period 2 duration: ' .\n    $stopwatch-\u003egetLastTime()-\u003easNanoSeconds() .\n    ' ns' .\n    PHP_EOL;\n\n/* Summa of all time periods */\necho (new DateTimeImmutable())-\u003eformat('s.u') .\n    ' Periods 1 + 2 summary duration: ' .\n    $stopwatch-\u003egetSummaryTime()-\u003easNanoSeconds() .\n    ' ns' .\n    PHP_EOL;\n\n/* Overall time */\necho (new DateTimeImmutable())-\u003eformat('s.u') .\n    ' Whole process duration: ' .\n    $stopwatch-\u003egetWholeTime()-\u003easNanoSeconds() .\n    ' ns' .\n    PHP_EOL;\n```\n\n```bash\n02.380004\n02.380020 Period 1 duration: 12400 ns\n02.380032 Period 2 duration: 3600 ns\n02.380035 Periods 1 + 2 summary duration: 16000 ns\n02.380044 Whole process duration: 24000 ns\n```\n\n## Using a stopwatch to benchmark any process\n\n```php\n$stopwatch = new SbWereWolf\\Stopwatch\\HRTimeStopwatch();\n$benchmark = new SbWereWolf\\Stopwatch\\Benchmark($stopwatch);\n\n$delay = 100;\necho \"Variable value before step z callback `$delay`\" . PHP_EOL;\n/* Variable value before step z callback `100` */\n$benchmark-\u003estep('z', function () use ($delay) {\n    time_nanosleep(0, $delay);\n    $delay++;\n});\necho \"after step z callback `$delay`\" . PHP_EOL;\n/* after step z callback `100` */\n/* Variable does not change its value */\n\n$benchmark-\u003estep('x', function () use (\u0026$delay) {\n    time_nanosleep(0, $delay);\n    $delay += 999;\n});\necho \"after step x callback `$delay`\" . PHP_EOL;\n/* after step x callback `1099` */\n/* Variable does change its value */\n\n$benchmark-\u003estep('c', function () use (\u0026$delay) {\n    $delay -= 999;\n    time_nanosleep(0, $delay);\n});\necho \"after step c callback `$delay`\" . PHP_EOL;\n/* after step c callback `100` */\n/* Variable does change its value */\n\necho \"Benchmark steps measurement is:\" . PHP_EOL;\n$i=0;\nforeach ($benchmark-\u003ereport() as $desc =\u003e $val) {\n    /** @var SbWereWolf\\Stopwatch\\ITimerReadings $val */\n    echo \"$desc =\u003e {$val-\u003easNanoSeconds()} ns\" . PHP_EOL;\n    $i++;\n}\n\n$totalNanoseconds = $benchmark-\u003etotal()-\u003easNanoSeconds();\necho \"Total is $totalNanoseconds ns\";\n```\n\n```bash\nvariable value before step z `100`\nafter step z `100`\nafter step x `1099`\nafter step c `100`\nBenchmark steps measurement is:\nz =\u003e 15800 ns\nx =\u003e 7600 ns\nc =\u003e 4100 ns\nTotal is 27500 ns\n```\n\n## Contacts\n\n```\nVolkhin Nikolay\ne-mail ulfnew@gmail.com\nphone +7-902-272-65-35\nTelegram @sbwerewolf\n```\n\nChat with me via messenger\n\n- [Telegram chat with me](https://t.me/SbWereWolf)\n- [WhatsApp chat with me](https://wa.me/79022726535) ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbwerewolf%2Fstopwatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbwerewolf%2Fstopwatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbwerewolf%2Fstopwatch/lists"}