{"id":13447452,"url":"https://github.com/nolanlawson/marky","last_synced_at":"2025-04-11T03:29:35.748Z","repository":{"id":41268500,"uuid":"74048404","full_name":"nolanlawson/marky","owner":"nolanlawson","description":"High-resolution JavaScript timer based on performance.mark/measure (491 bytes min+gz)","archived":false,"fork":false,"pushed_at":"2022-07-04T18:08:59.000Z","size":337,"stargazers_count":1096,"open_issues_count":0,"forks_count":43,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-10-29T15:34:53.379Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nolanlawson.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":"2016-11-17T16:59:29.000Z","updated_at":"2024-10-23T00:55:59.000Z","dependencies_parsed_at":"2022-08-02T13:17:02.091Z","dependency_job_id":null,"html_url":"https://github.com/nolanlawson/marky","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanlawson%2Fmarky","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanlawson%2Fmarky/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanlawson%2Fmarky/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanlawson%2Fmarky/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nolanlawson","download_url":"https://codeload.github.com/nolanlawson/marky/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248335236,"owners_count":21086540,"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-07-31T05:01:18.130Z","updated_at":"2025-04-11T03:29:35.729Z","avatar_url":"https://github.com/nolanlawson.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"marky\n======\n\nJavaScript timer based on `performance.mark()` and `performance.measure()`, providing [high-resolution\ntimings](https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API) as well as nice Dev Tools visualizations.\n\nFor browsers that don't support `performance.mark()`, it falls back to \n`performance.now()` or `Date.now()`. In Node, it uses `process.hrtime()`.\n\nQuick start\n----\n\nInstall via npm:\n\n    npm install marky\n\nOr as a script tag:\n\n```html\n\u003cscript src=\"https://unpkg.com/marky/dist/marky.min.js\"\u003e\u003c/script\u003e\n```\n\nThen take some measurements:\n\n```js\nvar marky = require('marky');\n\nmarky.mark('expensive operation');\ndoExpensiveOperation();\nmarky.stop('expensive operation');\n```\n\nWhy?\n---\n\nThe [User Timing API](https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API) is [more performant](https://gist.github.com/paulirish/2fad3834e2617fb199bc12e17058dde4)\nthan `console.time()` and `console.timeEnd()`,\nand [more accurate](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now) than `Date.now()`. Also, you get nice visualizations in Chrome Dev Tools:\n\n![Chrome Dev Tools screenshot](doc/chrome.png)\n\nAs well as Edge F12 Tools:\n\n![Edge F12 screenshot](doc/edge.png)\n\nThis is because `marky` adds standard\n[PerformanceEntries](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry) to the [Performance Timeline](https://developer.mozilla.org/en-US/docs/Web/API/Performance_Timeline). Tools like [WebPageTest](http://blog.patrickmeenan.com/2013/07/measuring-performance-of-user-experience.html) and [Windows Performance Analyzer](https://blogs.windows.com/msedgedev/2016/05/11/top-down-analysis-wpt/) also surface them, and you can even [send them to your analytics provider](https://github.com/googlecodelabs/performance-analytics).\n\nAPI\n---\n\n`marky.mark()` begins recording, and `marky.stop()` finishes recording:\n\n```js\nmarky.mark('releaseTheHounds');\nreleaseTheHounds();\nmarky.stop('releaseTheHounds');\n```\n\nYou can also do more complex scenarios:\n\n```js\nfunction setSail() {\n  marky.mark('setSail');\n  marky.mark('raiseTheAnchor');\n  raiseTheAnchor();\n  marky.stop('raiseTheAnchor');\n  marky.mark('unfurlTheSails');\n  unfurlTheSails();\n  marky.stop('unfurlTheSails');\n  marky.stop('setSail');\n}\n```\n\n`marky.stop()` also returns a `PerformanceEntry`:\n\n```js\nmarky.mark('manTheTorpedos');\nmanTheTorpedos();\nvar entry = marky.stop('manTheTorpedos');\n```\n\nThe entry will look something like:\n\n```json\n{\n  \"entryType\": \"measure\",\n  \"startTime\": 1974112,\n  \"duration\": 350,\n  \"name\": \"manTheTorpedos\"\n}\n```\n\nYou can get all entries using:\n\n```js\nvar entries = marky.getEntries();\n```\n\nThis provides a list of all measures ordered by `startTime`, e.g.:\n\n```json\n[\n  {\n    \"entryType\": \"measure\",\n    \"startTime\": 1974112,\n    \"duration\": 350,\n    \"name\": \"numberOne\"\n  },\n  {\n    \"entryType\": \"measure\",\n    \"startTime\": 1975108,\n    \"duration\": 300,\n    \"name\": \"numberTwo\"\n  },\n  {\n    \"entryType\": \"measure\",\n    \"startTime\": 1976127,\n    \"duration\": 250,\n    \"name\": \"numberThree\"\n  }\n]\n```\n\nYou can also clear the entries using `marky.clear():`\n\n```js\nmarky.clear()\n```\n\nAfter this, `marky.getEntries()` will return an empty list. (If the User Timing API is supported, this will delete all the `mark` and `measure` entries from the timeline.)\n\nBrowser support\n----\n\n`marky` has been tested in the following browsers/environments:\n\n* IE 9+\n* Safari 8+\n* iOS 8+\n* Android 4.4+\n* Chrome\n* Firefox\n* Edge\n* Node 4+\n\nPer [the spec](https://www.w3.org/TR/resource-timing-1/#extensions-performance-interface), browsers only need to hold a minimum\nof 150 entries in their Performance Timeline buffer. [In older versions of Firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=1331135), the buffer\nis throttled to 150, which for `marky`\nmeans you can get a maximum of 50 entries from `marky.getEntries()` (because `marky` creates two marks and a measure).\n\nIf you need to get more than 50 entries from `marky.getEntries()`, you can do:\n\n```js\nif (typeof performance !== 'undefined' \u0026\u0026 performance.setResourceTimingBufferSize) {\n  performance.setResourceTimingBufferSize(10000); // or however many you need\n}\n```\n\nIn Node and [browsers that don't support the User Timing API](http://caniuse.com/#feat=user-timing),\n`marky` follows the behavior of Edge and Chrome, and does not limit the number of entries. `marky.stop()` and \n`marky.getEntries()` will return pseudo-`PerformanceEntry` objects.\n\nSee also\n---\n\n- [appmetrics.js](https://github.com/ebidel/appmetrics.js) – a library on top of `mark()`/`measure()` which reports to Google Analytics.\n\nCredits\n----\n\nThanks to [@toddreifsteck](https://github.com/toddreifsteck) for feedback on this project and clarifications on the User Timing API.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolanlawson%2Fmarky","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnolanlawson%2Fmarky","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolanlawson%2Fmarky/lists"}