{"id":13817405,"url":"https://github.com/simonepri/sympact","last_synced_at":"2025-04-05T06:08:45.102Z","repository":{"id":65511481,"uuid":"126248809","full_name":"simonepri/sympact","owner":"simonepri","description":"🔥 Stupid Simple CPU/MEM \"Profiler\" for your JS code.","archived":false,"fork":false,"pushed_at":"2018-05-28T13:59:10.000Z","size":278,"stargazers_count":441,"open_issues_count":2,"forks_count":18,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-29T05:09:33.173Z","etag":null,"topics":["benchmark","cli","cpu","damage","impact","memory","nodejs","pid","pids","process","profile","resources","system","usage"],"latest_commit_sha":null,"homepage":"","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/simonepri.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"license","code_of_conduct":".github/code-of-conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-21T22:37:36.000Z","updated_at":"2025-02-08T21:32:24.000Z","dependencies_parsed_at":"2023-01-26T18:45:20.453Z","dependency_job_id":null,"html_url":"https://github.com/simonepri/sympact","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonepri%2Fsympact","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonepri%2Fsympact/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonepri%2Fsympact/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonepri%2Fsympact/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonepri","download_url":"https://codeload.github.com/simonepri/sympact/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294539,"owners_count":20915340,"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":["benchmark","cli","cpu","damage","impact","memory","nodejs","pid","pids","process","profile","resources","system","usage"],"created_at":"2024-08-04T06:00:42.402Z","updated_at":"2025-04-05T06:08:45.079Z","avatar_url":"https://github.com/simonepri.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/simonepri/sympact\"\u003e\n    \u003cimg src=\"https://github.com/simonepri/sympact/raw/master/media/sympact.png\" alt=\"sympact\" width=\"150\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003c!-- CI - TravisCI --\u003e\n  \u003ca href=\"https://travis-ci.org/simonepri/sympact\"\u003e\n    \u003cimg src=\"https://img.shields.io/travis/simonepri/sympact/master.svg?label=MacOS%20%26%20Linux\" alt=\"Mac/Linux Build Status\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- CI - AppVeyor --\u003e\n  \u003ca href=\"https://ci.appveyor.com/project/simonepri/sympact\"\u003e\n    \u003cimg src=\"https://img.shields.io/appveyor/ci/simonepri/sympact/master.svg?label=Windows\" alt=\"Windows Build status\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Coverage - Codecov --\u003e\n  \u003ca href=\"https://codecov.io/gh/simonepri/sympact\"\u003e\n    \u003cimg src=\"https://img.shields.io/codecov/c/github/simonepri/sympact/master.svg\" alt=\"Codecov Coverage report\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- DM - Snyk --\u003e\n  \u003ca href=\"https://snyk.io/test/github/simonepri/sympact?targetFile=package.json\"\u003e\n    \u003cimg src=\"https://snyk.io/test/github/simonepri/sympact/badge.svg?targetFile=package.json\" alt=\"Known Vulnerabilities\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- DM - David --\u003e\n  \u003ca href=\"https://david-dm.org/simonepri/sympact\"\u003e\n    \u003cimg src=\"https://david-dm.org/simonepri/sympact/status.svg\" alt=\"Dependency Status\" /\u003e\n  \u003c/a\u003e\n\n  \u003cbr/\u003e\n\n  \u003c!-- Code Style - XO-Prettier --\u003e\n  \u003ca href=\"https://github.com/xojs/xo\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/code_style-XO+Prettier-5ed9c7.svg\" alt=\"XO Code Style used\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Test Runner - AVA --\u003e\n  \u003ca href=\"https://github.com/avajs/ava\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/test_runner-AVA-fb3170.svg\" alt=\"AVA Test Runner used\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Test Coverage - Istanbul --\u003e\n  \u003ca href=\"https://github.com/istanbuljs/nyc\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/test_coverage-NYC-fec606.svg\" alt=\"Istanbul Test Coverage used\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Init - ni --\u003e\n  \u003ca href=\"https://github.com/simonepri/ni\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/initialized_with-ni-e74c3c.svg\" alt=\"NI Scaffolding System used\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Release - np --\u003e\n  \u003ca href=\"https://github.com/sindresorhus/np\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/released_with-np-6c8784.svg\" alt=\"NP Release System used\" /\u003e\n  \u003c/a\u003e\n\n  \u003cbr/\u003e\n\n  \u003c!-- Version - npm --\u003e\n  \u003ca href=\"https://www.npmjs.com/package/sympact\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/sympact.svg\" alt=\"Latest version on npm\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- License - MIT --\u003e\n  \u003ca href=\"https://github.com/simonepri/sympact/tree/master/license\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/simonepri/sympact.svg\" alt=\"Project license\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  🔥 An easy way to calculate the 'impact' of running a task in Node.JS\n  \u003cbr/\u003e\n\n  \u003csub\u003e\n    Coded with ❤️ by \u003ca href=\"#authors\"\u003eSimone Primarosa\u003c/a\u003e.\n  \u003c/sub\u003e\n\u003c/p\u003e\n\n## Synopsis\n\nSympact runs a script and profiles its execution time, CPU usage, and memory usage. Sympact then returns an execution report containing the averages of the results.\n\nDo you believe that this is *useful*?\nHas it *saved you time*?\nOr maybe you simply *like it*?  \nIf so, [show your appreciation with a Star ⭐️][start].\n\n## How it works\n\nsympact spawns a separate process and runs your script in an isolated\nnode process and then collects statistics about the system's resource used by\nyour script.\n\nThe data are collected using [pidusage][gh:pidusage] in combination with\n[pidtree][gh:pidtree].  \n**The main difference between other projects is that sympact will also\n\"profile\" processes spawned by your script or by any of its children.**\n\nFinally a report of the samples taken is computed and returned to you.\n\n## Install\n\n```bash\nnpm install --save sympact\n```\n\n## Usage\n\n```js\nconst impact = require('sympact');\n\nconst report = await impact(`\n  let r = 2;\n  let c = 10e7;\n  while (c--) r = Math.pow(r, r);\n  return r;\n`, {interval: 125}); // 125 ms of sampling rate\n\nconsole.log(report.times.execution.end - report.times.execution.start);\n// =\u003e 2700 ms\nconsole.log(report.stats.cpu.mean);\n// =\u003e 90.45 % on my machine\nconsole.log(report.stats.memory.mean);\n// =\u003e 27903317.33 bytes on my machine\n```\n\n## CLI\n\n\u003cimg src=\"https://github.com/simonepri/sympact/raw/master/media/cli.gif\" alt=\"sympact CLI\" width=\"475\" align=\"right\"/\u003e\n\nTo make it more usable, a CLI is bundled with the package allowing for an aesthetically pleasing report.\n\n```bash\n  npx sympact \"console.log('Hello World')\"\n```\n\nYou can even require other files.\n```bash\n  npx sympact \"\n    const {spawn} = require('child_process');\n    let childno = 10;\n    let childs = [];\n    for (let i = 0; i \u003c childno; i++) {\n      childs.push(spawn('node', ['-e', 'setInterval(()=\u003e{let c=10e3;while(c--);},10)']));\n    }\n    let c = 10e6;\n    let m = {};\n    while (c--)  m[c] = c;\n    for (let i = 0; i \u003c childno; i++) {\n      childs[i].kill();\n    }\n  \"\n```\n\u003cbr/\u003e\u003cbr/\u003e\n\n## Report object\n\nThe object returned by the promise will look like this.\n```js\n{\n  \"times\": {\n    \"sampling\": {\n      \"start\": 1521666020917,          // ms since epoch\n      \"end\": 1521666036041             // ms since epoch\n    },\n    \"execution\": {\n      \"start\": 1521666020958,          // ms since epoch\n      \"end\": 1521666036006             // ms since epoch\n    }\n  },\n  \"stats\": {\n    \"cpu\": {                           // CPU usage statistics (percentage)\n      \"mean\": 74.17368421052636,\n      \"median\": 75.1,\n      \"stdev\": 11.820700343128212,\n      \"max\": 94.7,\n      \"min\": 0.7\n    },\n    \"memory\": {                        // RAM usage statistics (bytes)\n      \"mean\": 1080202186.1052632,\n      \"median\": 1327509504,\n      \"stdev\": 416083837.44653314,\n      \"max\": 1327513600,\n      \"min\": 23441408\n    }\n  },\n  \"samples\": {                         // List of all the samples taken\n    \"period\": 125,                     // Sampling period\n    \"count\": 114,                      // Number of samples taken\n    \"list\": {\n      \"39\": {                          // Taken after 39ms after the start of the watch command\n        \"cpu\": 0.7,                    // Sum of the usages of all the processes\n        \"memory\": 23441408,            // Sum of the memory of all the processes\n        \"processes\": [{                // List of processes profiled in this timeframe\n          \"cpu\": 0.7,\n          \"memory\": 23441408,\n          \"ppid\": 837,\n          \"pid\": 839,\n          \"ctime\": 6000,\n          \"elapsed\": 1000,\n          \"timestamp\": 1521666020955   // ms since epoch\n        }]\n      },\n      \"205\": {\n        \"cpu\": 14.8,\n        \"memory\": 55685120,\n        \"processes\": [{\n          \"cpu\": 14.8,\n          \"memory\": 55685120,\n          \"ppid\": 837,\n          \"pid\": 839,\n          \"ctime\": 15000,\n          \"elapsed\": 2000,\n          \"timestamp\": 1521666021122\n        }]\n      },\n\n      [...]\n\n      \"15124\": {\n        \"cpu\": 81.2,\n        \"memory\": 878133248,\n        \"processes\": [{\n          \"cpu\": 81.2,\n          \"memory\": 878133248,\n          \"ppid\": 837,\n          \"pid\": 839,\n          \"ctime\": 47600,\n          \"elapsed\": 17000,\n          \"timestamp\": 1521666036041\n        }]\n      }\n    }\n  }\n}\n```\n\n## API\n\n\u003ca name=\"sympact\"\u003e\u003c/a\u003e\n\n### sympact(code, [options]) ⇒ \u003ccode\u003ePromise.\u0026lt;Object\u0026gt;\u003c/code\u003e\nMeasures the impact of running a certain script on your system.\nMonitors the cpu and memory usage of the whole tree of processes generated by\nthe script provided.\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;Object\u0026gt;\u003c/code\u003e - An object containing the results.  \n**Access**: public  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| code | \u003ccode\u003estring\u003c/code\u003e |  | The source code to test. |\n| [options] | \u003ccode\u003eObject\u003c/code\u003e |  | Optional configurations. |\n| [options.interval] | \u003ccode\u003enumber\u003c/code\u003e | \u003ccode\u003e125\u003c/code\u003e | Sampling interval in milliseconds. |\n| [options.cwd] | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;caller path\u0026quot;\u003c/code\u003e | CWD for the script. |\n\n## Contributing\n\nContributions are REALLY welcome and if you find a security flaw in this code, PLEASE [report it][new issue].  \nPlease check the [contributing guidelines][contributing] for more details. Thanks!\n\n## Authors\n\n- **Simone Primarosa** -  *Follow* me on *Github* ([:octocat:@simonepri][github:simonepri]) and on  *Twitter* ([🐦@simonepri][twitter:simoneprimarosa])\n\nSee also the list of [contributors][contributors] who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [license][license] file for details.\n\n\u003c!-- Links --\u003e\n[start]: https://github.com/simonepri/sympact#start-of-content\n[new issue]: https://github.com/simonepri/sympact/issues/new\n[contributors]: https://github.com/simonepri/sympact/contributors\n\n[license]: https://github.com/simonepri/sympact/tree/master/license\n[contributing]: https://github.com/simonepri/sympact/tree/master/.github/contributing.md\n\n[github:simonepri]: https://github.com/simonepri\n[twitter:simoneprimarosa]: http://twitter.com/intent/user?screen_name=simoneprimarosa\n\n[gh:pidusage]: https://github.com/soyuka/pidusage\n[gh:pidtree]: https://github.com/simonepri/pidtree\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonepri%2Fsympact","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonepri%2Fsympact","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonepri%2Fsympact/lists"}