{"id":17222828,"url":"https://github.com/onury/perfy","last_synced_at":"2025-08-20T22:31:48.666Z","repository":{"id":1756445,"uuid":"44076004","full_name":"onury/perfy","owner":"onury","description":"A simple, light-weight NodeJS utility for measuring code execution in high-resolution real times.","archived":false,"fork":false,"pushed_at":"2022-02-11T10:37:02.000Z","size":1274,"stargazers_count":55,"open_issues_count":6,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-03T04:50:32.651Z","etag":null,"topics":["benchmark","execution","javascript","performance","time"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/onury.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":"2015-10-12T00:53:22.000Z","updated_at":"2023-11-05T18:06:39.000Z","dependencies_parsed_at":"2022-08-06T11:01:10.324Z","dependency_job_id":null,"html_url":"https://github.com/onury/perfy","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/onury/perfy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onury%2Fperfy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onury%2Fperfy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onury%2Fperfy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onury%2Fperfy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onury","download_url":"https://codeload.github.com/onury/perfy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onury%2Fperfy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271397955,"owners_count":24752640,"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-08-20T02:00:09.606Z","response_time":69,"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":["benchmark","execution","javascript","performance","time"],"created_at":"2024-10-15T04:06:27.276Z","updated_at":"2025-08-20T22:31:48.362Z","avatar_url":"https://github.com/onury.png","language":"JavaScript","readme":"# perfy\n\n[![npm](http://img.shields.io/npm/v/perfy.svg)](https://www.npmjs.com/package/perfy)\n[![release](https://img.shields.io/github/release/onury/perfy.svg)](https://github.com/onury/perfy)\n[![downloads](http://img.shields.io/npm/dm/perfy.svg)](https://www.npmjs.com/package/perfy)\n[![license](http://img.shields.io/npm/l/perfy.svg)](https://github.com/onury/perfy/blob/master/LICENSE)\n\nA simple, light-weight Node.js utility for measuring code execution performance in high-resolution real times.\n\n\u003e © 2021, Onur Yıldırım ([@onury][onury]). MIT License.\n\n## Installation\n\n```sh\n    npm install perfy --save\n```\n\n## Usage\n\n```js\nvar perfy = require('perfy');\n```\n\nSimple. Just call `perfy.start('name')` and the performance instance will be created and start time will be set until you call `perfy.end('name')` which returns a result object containing the high-res elapsed time information (and destroys the created instance).\n\n```js\nperfy.start('loop-stuff');\n// some heavy stuff here...\nvar result = perfy.end('loop-stuff');\nconsole.log(result.time); // —\u003e 1.459 (sec.)\n```\n... or you could:\n```js\nperfy.exec('async-stuff', function (done) {\n    // some heavy stuff here...\n    var result = done();\n    console.log(result.time); // —\u003e 1.459 (sec.)\n});\n```\n\n## Documentation\n\n### `.start(name [, autoDestroy])`\nInitializes a new performance instance with the given name; and marks the current high-resolution real time.\n\n**Parameters:**\n\n - *name* `String` — Required. Unique name of the performance instance to be started. Setting an existing name will overwrite this item. Use `.exists()` method to check for existence.\n - *autoDestroy* `Boolean` — Optional. Default: `true`. Specifies whether this performance instance should be destroyed when `.end()` is called.\n\n**returns** `perfy`\n\n### `.end(name)`\nEnds the performance instance with the given name; and calculates the elapsed high-resolution real time. Note that if `autoDestroy` is not disabled when `.start()` is called; corresponding performance instance is immediately destroyed after returning the result.\n\n**Parameters:**\n\n - *name* `String` — Required. Unique name of the performance instance to be ended.\n\n**returns** `Object` — A result object with the following properties.\n\n - *name* `String` — Initialized name of the performance instance.\n - *seconds* `Number` — Seconds portion of the elapsed time. e.g. `1`\n - *milliseconds* `Number` — Nanoseconds portion converted to milliseconds. `235.125283`\n - *nanoseconds* `Number` — Nanoseconds portion of the elapsed time. e.g. `235125283`\n - *time* `Number` — Float representation of full elapsed time in seconds. e.g. `1.235`\n - *fullSeconds* `Number` — Alias of `.time`.\n - *fullMilliseconds* `Number` — Float representation of full elapsed time in milliseconds. e.g. `1235.125`\n - *fullNanoseconds* `Number` — Float representation of full elapsed time in nanoseconds. e.g. `1235125283`\n - *summary* `String` — Text summary shorthand for elapsed time.\n - *startTime* `Number` — UTC start time of the execution (low-resolution). e.g. `1533302465251`\n - *endTime* `Number` — UTC end time of the execution (low-resolution). e.g. `1533302466486`\n\n### `.exec([name,] fn)`\nInitializes a new performance instance right before executing the given function, and automatically ends after the execution is done.\n\n**Parameters:**\n\n - *name* `String` — Optional. Unique name of the performance instance. Set this if you want the keep the instance for later use (such as getting the result at a later time).\n - *fn* `Function` — Required. Function to be executed. This function is invoked with an optional `done` argument which is only required if you are running an asynchronous operation. You should omit the `done` argument if it's a synchronous operation.\n\n**returns** `Object|perfy` — Returns a result object if running a **synchronous** operation (by omitting `done`).\n```js\nfunction syncOp() {\n    // sync operation\n}\nvar result = perfy.exec(syncOp);\n```\nOtherwise (if **asynchronous**), immediately returns the `perfy` object and result will be returned by calling `done()` from within `fn`.\n```js\nperfy.exec(function (done) {\n    // a-sync operation\n    var result = done();\n    // perfy.count() === 0 // (auto-destroyed)\n});\n```\nYou can also save this performance instance by setting the name.\n```js\nperfy.exec('async-op', function (done) {\n    // a-sync operation\n    done();\n    perfy.exists('async-op'); // —\u003e true (saved)\n});\n```\n\n### `.result(name)`\nGets the calculated result of the performance instance for the given name. To be used with non-destroyed, ended instances. If instance is not yet ended or does not exist at all, returns `null`.\n\n**Parameters:**\n\n - *name* `String` — Required. Unique name of the performance instance.\n\n**returns** `Object` — A result object (see `.end()` method).\n\n### `.exists(name)`\nSpecifies whether a performance instance exists with the given name. This method will return `false` for an item, if called after `.end(name)` is called since the instance is destroyed.\n\n**Parameters:**\n\n - *name* `String` — Required. Name of the performance instance to be checked.\n\n**returns** `Boolean`\n\n### `.destroy(name)`\nDestroys the performance instance with the given name.\n\n**Parameters:**\n\n - *name* `String` — Required. Name of the performance instance to be destroyed.\n\n**returns** `perfy`\n\n### `.destroyAll()`\nDestroys all existing performance instances.\n\n**returns** `perfy`\n\n### `.names()`\nGets the names of existing performance instances.\n\n**returns** `Array`\n\n### `.count()`\nGets the total number of existing performance instances.\n\n**returns** `Number`\n\n## More Examples:\n\nBasic:\n```js\nperfy.start('metric-1');\nvar result1 = perfy.end('metric-1');\nconsole.log(result1.seconds + ' sec, ' + result1.milliseconds.toFixed(3) + ' ms.');\n// —\u003e 1 sec, 234 ms.\n// OR\nconsole.log(result1.time + ' sec. ');\n// —\u003e 1.234 sec.\n```\n\nAuto-Destroy:\n```js\nperfy.start('metric-2').count(); // —\u003e 1 (metric-1 is already destroyed)\nvar result2 = perfy.end('metric-2');\nperfy.count(); // —\u003e 0 (metric-2 is also destroyed after .end() is called)\n```\n\nKeep the instance (disable `autoDestroy`):\n```js\nperfy.start('metric-3', false);\nperfy.end('metric-3').time; // —\u003e 0.123\nperfy.exists('metric-3'); // —\u003e true\n```\n\nDestroy all:\n```js\nperfy.destroyAll().count(); // —\u003e 0\n```\n\nSave/exec async:\n```js\nperfy\n    .exec('async-op', function (done) {\n        var result = done(); // === perfy.result('async-op')\n        perfy.count(); // 1\n    })\n    .count(); // 0 (sync)\n```\n\n## Changelog\n\n- **v1.1.5** (2018-08-03)\n    + Added `.fullMilliseconds` to result object. (PR [#2](https://github.com/onury/perfy/pull/2) by [@anho](https://github.com/anho))\n    + Added `.fullNanoseconds` and `.fullSeconds` (alias of `.time`) to result object.\n    + (Dev) Removed grunt in favour of npm scripts.\n\n    ---\n\n- **v1.1.2** (2016-03-23)\n    + Fixed `time` and `summary` padding issue. (PR [#1](https://github.com/onury/perfy/pull/1) by [@gunnarlium](https://github.com/gunnarlium))\n    + Other minor dev improvements.\n\n    ---\n\n- **v1.1.0** (2015-10-16)\n    + Added `.exec()` convenience method.\n    + `.exists()` will throw if no `name` is specified.\n\n    ---\n\n- **v1.0.1** (2015-10-12)\n    + `.result(name)` will not throw (and return `null`) even if the perf-instance does not exist. It will throw if no name is specified.\n\n    ---\n\n- **v1.0.0** (2015-10-12)\n    + First release.\n\n    ---\n\n\n[onury]:https://github.com/onury\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonury%2Fperfy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonury%2Fperfy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonury%2Fperfy/lists"}