{"id":15470510,"url":"https://github.com/austindd/rescript-benchmarkjs","last_synced_at":"2025-10-27T23:31:10.328Z","repository":{"id":65031307,"uuid":"327716449","full_name":"austindd/rescript-benchmarkjs","owner":"austindd","description":"ReScript bindings to the Benchmark.js library","archived":false,"fork":false,"pushed_at":"2021-02-26T23:12:57.000Z","size":42,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T06:53:40.302Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"ReScript","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/austindd.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":"2021-01-07T20:21:14.000Z","updated_at":"2025-01-19T04:00:13.000Z","dependencies_parsed_at":"2022-12-28T20:20:49.168Z","dependency_job_id":null,"html_url":"https://github.com/austindd/rescript-benchmarkjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/austindd%2Frescript-benchmarkjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/austindd%2Frescript-benchmarkjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/austindd%2Frescript-benchmarkjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/austindd%2Frescript-benchmarkjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/austindd","download_url":"https://codeload.github.com/austindd/rescript-benchmarkjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238569864,"owners_count":19493939,"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-10-02T02:05:10.995Z","updated_at":"2025-10-27T23:31:09.983Z","avatar_url":"https://github.com/austindd.png","language":"ReScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rescript-benchmarkjs\nReScript bindings to [Benchmark.js](https://github.com/bestiejs/benchmark.js/), an excellent performance benchmarking library.\n\n## Installation\n\nUsing `npm`:\n```shell\nnpm install --save-dev rescript-benchmarkjs\n```\n\nUsing `yarn`:\n```shell\nyarn add --dev rescript-benchmarkjs\n```\n\nDon't forget to add the dependency to your `bsconfig.json` file:\n```json\n{\n  \"bs-dev-dependencies\": [\n    \"rescript-benchmarkjs\"\n  ]\n}\n```\n\n## Usage\n\n```rescript\nopen BenchmarkJs\n\nlet suiteConfig = {\n  ...Suite.defaultConfig,\n  onStart: _ =\u003e Js.log(\"-- Running Benchmark Suite --\\r\\n\"),\n  onComplete: _ =\u003e Js.log(\"-- Benchmark Results --\\r\\n\"),\n}\n\nlet benchmarkConfig = {\n  ...Benchmark.defaultConfig,\n  onError: Js.log,\n  onStart: event =\u003e Js.log(\"Running: '\" ++ Benchmark.name(event.target) ++ \"'...\"),\n  onComplete: _ =\u003e Js.log(\"Done\\r\\n\"),\n}\n\nRandom.init(486)\nlet myArray = Belt.Array.makeBy(1000, _ =\u003e Random.int(99999))\n\nSuite.make(\"Array Sort\", ~config=suiteConfig)\n-\u003eSuite.add(\"Belt.SortArray.stableSortBy\", ~config=benchmarkConfig, (. ()) =\u003e {\n  let result = myArray-\u003eBelt.SortArray.stableSortBy(Pervasives.compare)\n  ignore(result)\n})\n-\u003eSuite.add(\"Js.Array2.slice + Js.Array2.sortInPlace\", ~config=benchmarkConfig, (. ()) =\u003e {\n  let result = myArray-\u003eJs.Array2.sliceFrom(0)-\u003eJs.Array2.sortInPlace\n  ignore(result)\n})\n-\u003eSuite.run\n-\u003eSuite.toArray\n-\u003eBelt.Array.map(Benchmark.toString)\n-\u003eBelt.Array.forEach(Js.log)\n```\n\n### Important Notes:\n\n1. One obvious difference bewteen the ReScript interface and the original `Benchmark.js` API is that, in ReScript, we cannot define \"setup code\" in one function, and then expect the values defined there to be available in a separate function defining a \"test case\". Therefore, any values you expect to be available within both the *setup function* AND a *test case function* must be defined in an outer (usually global) scope. This is done in the example above with the `myArray` value.\n2. It's generally a good idea to inspect the generated code for each test case. In some cases, you may find that the compiler has optimized or de-optimized a test case in unexpected ways. This might include code removal, adding/removing wrapper objects, using helper functions for type-safety, etc. In some cases, you might intend to capture this compiler behavior in your tests. In other cases, you may find yourself running tests with false assumptions about the generated JS code. Always check the generated code to be certain.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faustindd%2Frescript-benchmarkjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faustindd%2Frescript-benchmarkjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faustindd%2Frescript-benchmarkjs/lists"}