{"id":16535411,"url":"https://github.com/hougesen/picobench","last_synced_at":"2025-10-09T10:33:56.052Z","repository":{"id":44327443,"uuid":"511948768","full_name":"hougesen/picobench","owner":"hougesen","description":"A pico (very small) library for testing performance of functions.","archived":false,"fork":false,"pushed_at":"2025-01-22T06:43:05.000Z","size":386,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-22T15:19:12.775Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/picobench","language":"TypeScript","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/hougesen.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-08T15:51:44.000Z","updated_at":"2024-09-25T10:16:09.000Z","dependencies_parsed_at":"2024-01-20T12:30:01.161Z","dependency_job_id":"b9e3a9b1-a639-4aa6-8202-5f5415d85e5a","html_url":"https://github.com/hougesen/picobench","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/hougesen/picobench","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hougesen%2Fpicobench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hougesen%2Fpicobench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hougesen%2Fpicobench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hougesen%2Fpicobench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hougesen","download_url":"https://codeload.github.com/hougesen/picobench/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hougesen%2Fpicobench/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001267,"owners_count":26083040,"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-10-09T02:00:07.460Z","response_time":59,"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":[],"created_at":"2024-10-11T18:27:23.995Z","updated_at":"2025-10-09T10:33:56.035Z","avatar_url":"https://github.com/hougesen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# picobench\n\nA pico (very small) library for testing performance of functions. Meant to be used in combination with a unit test framework like Vitest or Jest\n\n[![ci](https://github.com/hougesen/picobench/workflows/ci/badge.svg)](https://github.com/hougesen/picobench/actions/workflows/ci.yml)\n[![npm-publish](https://github.com/hougesen/picobench/workflows/npm-publish/badge.svg)](https://github.com/hougesen/picobench/actions/workflows/npm-publish.yml)\n[![npm version](https://badge.fury.io/js/picobench.svg)](https://badge.fury.io/js/picobench)\n\n## Note for TypeScript users\n\nIf you are using TypeScript, you should consider transpiling your project first, and then running the benchmark against the transpiled code. This will give a more precise result.\n\n## Installation\n\n```sh\nnpm i -D picobench\n```\n\n## Usage\n\nTo benchmark function you should use [benchSync](./src/lib/benchSync.ts) for synchronous code, and [benchAsync](./src/lib/benchAsync.ts) for asynchronous code.\n\nThe output of the timing functions look like the following:\n\n```ts\ninterface IBenchResult {\n    /**\n     * @summary operations per seconds\n     * @calculation 1 / (average_in_ms / 1000)\n     */\n    ops: number;\n    /**\n     * @summary averate time to run in milliseconds\n     */\n    average: number;\n    /**\n     * @summary median time to run in milliseconds\n     */\n    median: number;\n    /**\n     * @summary slowest run in milliseconds\n     */\n    minimum: number;\n    /**\n     * @summary fastest run in milliseconds\n     */\n    maximum: number;\n    /**\n     * @summary all runs in milliseconds\n     */\n    runs: number[];\n}\n```\n\n### Synchronous code\n\n```ts\nimport { benchSync } from 'picobench';\n// or\nconst { benchSync } = require('picobench');\n// or\nconst benchSync = require('picobench').benchSync;\n\nfunction dummyFn() {\n    let sum = 0;\n    for (let i = 0; i \u003c 1000000; i += 1) sum += 1;\n    return sum;\n}\n\nconst benchmarkResult = benchSync(dummyFn);\n\n//  {\n//      ops: 1052.6315789473683,\n//      average: 0.95,\n//      median: 0.9604999999999999,\n//      minimum: 0.903,\n//      maximum: 0.97,\n//      runs: [0.903, 0.908, 0.951, 0.958, 0.96, 0.961, 0.961, 0.964, 0.964, 0.97]\n//  }\n```\n\n### Synchronous code\n\n```ts\nimport { benchSync } from 'picobench';\n// or\nconst { benchAsync } = require('picobench');\n// or\nconst benchAsync = require('picobench').benchSync;\n\nfunction dummyFn(n = 1000000): number {\n    let sum = 0;\n    for (let i = 0; i \u003c n; i += 1) sum += 1;\n    return sum;\n}\n\n// if the function doesn't take parameters you can call it like this\nconst benchmarkResult = benchSync(dummyFn);\n// otherwise you will have to call it with a callback function\nconst benchmarkResult = benchSync(() =\u003e dummyFn(10000));\n\n//  {\n//      ops: 1052.6315789473683,\n//      average: 0.95,\n//      median: 0.9604999999999999,\n//      minimum: 0.903,\n//      maximum: 0.97,\n//      runs: [0.903, 0.908, 0.951, 0.958, 0.96, 0.961, 0.961, 0.964, 0.964, 0.97]\n//  }\n```\n\n### Asynchronous code\n\n```ts\nimport { benchAsync } from 'picobench';\n// or\nconst { benchAsync } = require('picobench');\n// or\nconst benchAsync = require('picobench').benchAsync;\n\nasync function sleep(ms = 500) {\n    return new Promise((resolve) =\u003e setTimeout(resolve, ms));\n}\n\n// if the function doesn't take parameters you can call it like this\nconst benchmarkResult = await benchAsync(sleep);\n// otherwise you will have to call it like a callback function\nconst benchmarkResult = await benchAsync(() =\u003e await sleep(500));\n\n//  {\n//      ops: 1.996369801153583,\n//      average: 500.9091999999999,\n//      median: 500.87800000000004,\n//      minimum: 500.796,\n//      maximum: 501.292,\n//      runs: [500.796, 500.823, 500.851, 500.869, 500.877, 500.879, 500.894, 500.898, 500.913, 501.292]\n//  }\n```\n\n### Callbacks\n\nIf you wish to benchmark a function that needs parameters, you have to pass the function as a callback function.\n\n```ts\nimport { benchSync, benchAsync } from 'picobench';\n\nconst syncBenchmark = benchSync(() =\u003e {\n    callSomeSyncFunction('param1', 'param2');\n});\n\nconst asyncBenchmark = await benchAsync(async () =\u003e {\n    await callSomeAsyncFunc('param1', 'param2');\n});\n```\n\nThe same goes if you wish to benchmark code that isn't wrapped in a function already.\n\n```ts\nimport { benchSync } from 'picobench';\n\nconst syncBenchmark = benchSync(() =\u003e {\n    const numbers = 1000;\n    Array.from({ length: numbers }, () =\u003e Math.floor(Math.random() * numbers));\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhougesen%2Fpicobench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhougesen%2Fpicobench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhougesen%2Fpicobench/lists"}