{"id":17163007,"url":"https://github.com/amnuts/timer","last_synced_at":"2025-03-24T16:39:21.774Z","repository":{"id":56947287,"uuid":"296921452","full_name":"amnuts/timer","owner":"amnuts","description":"This is a ridiculously simple microsecond timer for you to use within your PHP applications.","archived":false,"fork":false,"pushed_at":"2023-07-28T17:44:08.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-29T21:54:34.429Z","etag":null,"topics":["php","simple","timer"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amnuts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-09-19T17:45:38.000Z","updated_at":"2023-07-28T17:43:12.000Z","dependencies_parsed_at":"2024-12-05T18:01:02.474Z","dependency_job_id":null,"html_url":"https://github.com/amnuts/timer","commit_stats":{"total_commits":2,"total_committers":2,"mean_commits":1.0,"dds":0.5,"last_synced_commit":"c26e99ee12f64b87ef151303975729b2d3b714f4"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amnuts%2Ftimer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amnuts%2Ftimer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amnuts%2Ftimer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amnuts%2Ftimer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amnuts","download_url":"https://codeload.github.com/amnuts/timer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245312864,"owners_count":20595054,"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":["php","simple","timer"],"created_at":"2024-10-14T22:47:30.805Z","updated_at":"2025-03-24T16:39:21.750Z","avatar_url":"https://github.com/amnuts.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Timer\n\nThis is a ridiculously simple microsecond timer for you to use within your PHP applications.\n\nIt starts the timer when you instantiate the class and from there you can `mark` points of delta along the way and `stop` the timer.\n\nReally; could it get simpler?\n\n# Usage examples\n\n```php\n\u003c?php\n\nuse Amnuts\\Datetime\\Timer;\n\n$timer = new Timer();\nsleep(5); // do something here\necho $timer-\u003estop();\n```\n\nand that'll give us the result of:\n\n```\nStarted 2020-09-19 16:06:52\nEnded 2020-09-19 16:06:57, total time 0d 0h 0m 5.000200s\n```\n\nSimple, but kinda boring.  However, if you have a function that you're wanting to time which has lots of parts, then it's useful to place markers throughout and see the difference between each part.\n\nFor example:\n\n```php\n\u003c?php\n\nuse Amnuts\\Datetime\\Timer;\n\n$timer = new Timer();\nsleep(1);\n$timer-\u003emark();\nsleep(2);\n$timer-\u003emark();\nsleep(3);\n$timer-\u003estop();\n\necho $timer;\n```\n\nwill give us the result of:\n\n```\nStarted 2020-09-19 16:11:59\n\tΔ 0d 0h 0m 1.000200s\n\tΔ 0d 0h 0m 2.000700s\nEnded 2020-09-19 16:12:05, total time 0d 0h 0m 6.001800s\n```\n\nThe `mark` method allows us to see the delta between each time it's marked.  But it can be even more helpful with supplying a message for the mark:\n\n```php\n\u003c?php\n\nuse Amnuts\\Datetime\\Timer;\n\n$timer = new Timer();\nsleep(1);\n$timer-\u003emark('Starting something slow');\nsleep(2);\n$timer-\u003emark('Ended that and going onto something even slower!');\nsleep(3);\n$timer-\u003estop();\n\necho $timer;\n```\n\nand that gives us:\n\n```\nStarted 2020-09-19 16:14:51\n\tΔ 0d 0h 0m 1.000700s (Starting something slow)\n\tΔ 0d 0h 0m 2.000700s (Ended that and going onto something even slower!)\nEnded 2020-09-19 16:14:57, total time 0d 0h 0m 6.001900s\n```\n\nAnd, to be honest, you don't even need to `stop` the timer to output the current delta.  You could just do this:\n\n```\n\u003c?php\n\nuse Amnuts\\Datetime\\Timer;\n\n$timer = new Timer();\nsleep(1);\necho $timer;\nsleep(2);\necho $timer;\n```\n\nwhich produces output such as:\n\n```\nStarted 2020-09-19 16:40:47, current delta 0d 0h 0m 1.000100s\nStarted 2020-09-19 16:40:47, current delta 0d 0h 0m 3.000700s\n```\n\n# License\n\nMIT: http://acollington.mit-license.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famnuts%2Ftimer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famnuts%2Ftimer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famnuts%2Ftimer/lists"}