{"id":17714535,"url":"https://github.com/dikendev/npm-benchmark-ts","last_synced_at":"2026-04-29T21:32:55.355Z","repository":{"id":228277965,"uuid":"773513867","full_name":"Dikendev/npm-benchmark-ts","owner":"Dikendev","description":"Benchmark and Data Visualization package","archived":false,"fork":false,"pushed_at":"2024-05-23T00:36:18.000Z","size":385,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-23T03:25:44.151Z","etag":null,"topics":["algorithms","chart","data-visualization","javascript","jest","library","npm-package","typescript","typescript-library"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/npm-benchmark-ts","language":"TypeScript","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/Dikendev.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":"2024-03-17T21:25:02.000Z","updated_at":"2024-07-20T04:38:35.879Z","dependencies_parsed_at":"2024-03-18T01:55:16.096Z","dependency_job_id":"0d10f932-7506-465d-860f-d3478b5d889a","html_url":"https://github.com/Dikendev/npm-benchmark-ts","commit_stats":null,"previous_names":["dikendev/benchmark"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dikendev%2Fnpm-benchmark-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dikendev%2Fnpm-benchmark-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dikendev%2Fnpm-benchmark-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dikendev%2Fnpm-benchmark-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dikendev","download_url":"https://codeload.github.com/Dikendev/npm-benchmark-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246458000,"owners_count":20780677,"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":["algorithms","chart","data-visualization","javascript","jest","library","npm-package","typescript","typescript-library"],"created_at":"2024-10-25T11:15:19.842Z","updated_at":"2026-04-29T21:32:55.316Z","avatar_url":"https://github.com/Dikendev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Benchmark and Data Visualization\n\nThis project was created to measure the execution time of algorithms. It's worth mentioning that shorter execution times don't necessarily is the best solution, however they provide a valuable metric for our projects. With this package, I aim to demonstrate how we can effectively measure execution time using minimal external libraries.\n\n## Installation\n\nTo install all the dependencies, use the package manager [npm](https://www.npmjs.com/) and use the follow:\n\n```bash\nnpm i npm-benchmark-ts\n```\n\nThe unique external library in this project is the [ChartJsImage](https://www.npmjs.com/package/chartjs-to-image/).\nThis library provides a ChartJsImage object. Import it, instantiate it, and set the necessary config.\n\n## Usage\n\nFirst need to import :\n\n```typescript\nimport { benchMark, BenchmarkFunctions } from \"npm-benchmark-ts\";\n```\n\nFor example, this method uses a for loop to sum an array of numbers:\n\n```typescript\nfunction sumNumberUsingFor(numbers: number[]): number {\n\tlet result: number = 0;\n\tfor (let i = 0; i \u003c numbers.length; i++) {\n\t\tresult += numbers[i];\n\t}\n\treturn result;\n}\n```\n\nAnd this method sums an array of numbers using the reduce built-in method in TypeScript:\n\n```typescript\nfunction sumNumberUsingReduce(numbers: number[]): number {\n\treturn numbers.reduce((acc, current) =\u003e acc + current, 0);\n}\n```\n\nTo compare the execution time, run the test to generate the image and JSON files as follows:\n\n```typescript\nconst arrayLength = 1000000;\nconst numberArray = generateArray(arrayLength);\n\nconst benchmark1: BenchmarkFunctions\u003cnumber, number\u003e = {\n\tfunctionDescription: \"forLoop\",\n\tfunctionUnderTest: () =\u003e SumMethods.sumNumberUsingFor(numberArray),\n\tdetail: \"Sum numbers using for\",\n};\n\nconst benchmark2: BenchmarkFunctions\u003cnumber, number\u003e = {\n\tfunctionDescription: \"reduce\",\n\tfunctionUnderTest: () =\u003e SumMethods.sumNumberUsingReduce(numberArray),\n\tdetail: \"Sum numbers using reduce\",\n};\n\nawait benchMark\u003cnumber, number\u003e(\"comparison_sum_methods\", [\n\tbenchmark1,\n\tbenchmark2,\n]);\n```\n\n## Chart Image Benchmark Result\n\nIf you want to generate a chart and json response you can pass the option parameter.\n\n```typescript\nconst options: Options = {\n\tdirPath: \"TMP\",\n};\n\nconst benchMarkResult = await benchMark\u003cnumber, number\u003e(\n\t\"comparison_sum_methods\",\n\t[benchmark1, benchmark2],\n\toptions\n);\n```\n\n## Chart Data Result\n\n![chart image](/TMP/comparison_sum_methods.png \"Result chart png image\")\n\n## JSON Data Result\n\n```json\n{\n\t\"forLoop\": {\n\t\t\"name\": \"forLoop\",\n\t\t\"duration\": 4.217916999012232\n\t},\n\t\"reduce\": {\n\t\t\"name\": \"reduce\",\n\t\t\"duration\": 14.500208999961615\n\t}\n}\n```\n\n## Conclusion\n\nBased on the benchmark results, it's evident that in this specific scenario, the method sumNumberUsingFor, which utilizes a for loop, is better than sumNumberUsingReduce, which use the built-in reduce method, in terms of execution time. The for loop method completes the task in approximately 4.218 milliseconds, while the reduce method takes around 14.500 milliseconds.\n\nHowever, it's important to note that the superiority of the for loop in this scenario may vary depending on different factors such as the size of the input array, the complexity of the operations within the methods, and the specific environment in which the code is executed. Therefore, while these benchmark results provide valuable insights into the performance of these methods under certain conditions, it's crucial to consider various scenarios and factors when determining the optimal approach for a given task.\n\n## Contributing\n\nPull requests are welcome \u003c3. Please make sure to update tests as appropriate.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdikendev%2Fnpm-benchmark-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdikendev%2Fnpm-benchmark-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdikendev%2Fnpm-benchmark-ts/lists"}