Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Jan 2, 2023
0 parents commit 61d84ad
Show file tree
Hide file tree
Showing 13 changed files with 1,125 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{json,yml}]
charset = utf-8
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.yarn/** linguist-vendored
.yarn/releases/* binary
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.DS_Store
*.log
node_modules/

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.pnp.*

lib/bs/
*.bs.js
823 changes: 823 additions & 0 deletions .yarn/releases/yarn-3.3.1.cjs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
yarnPath: .yarn/releases/yarn-3.3.1.cjs

nodeLinker: node-modules
nmMode: hardlinks-global
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Hyeseong Kim <hey@hyeseong.kim>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# rescript-tinybench

ReScript bindings to [tinybench](https://github.com/tinylibs/tinybench)

## Usage

```
open RescriptTinybench
let bench =
Bench.make(~time=100.0, ())
->Bench.add("switch 1", () => {
let a = ref(1)
let b = ref(2)
let c = a.contents
a := b.contents
b := c
})
->Bench.add("switch 2", () => {
let a = ref(1)
let b = ref(10)
a := b.contents + a.contents
b := a.contents - b.contents
a := b.contents - a.contents
})
let run = async () => {
await bench.run(.)
open Belt
bench.tasks->Array.forEach(task => {
switch task {
| {name, result: Some(result)} => {
Js.log(`Task name: ${name}`)
Js.log(`Average Time (ps): ${Float.toString(result.mean *. 1000.)}`)
Js.log(`Variance (ps): ${Float.toString(result.variance *. 1000.)}`)
Js.log("")
}
| {name} => Js.log(`Error occured while running bench ${name}`)
}
})
}
run()->ignore
```

## LICENSE

MIT
23 changes: 23 additions & 0 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "rescript-tinybench",
"suffix": ".bs.js",
"sources": [
{
"dir": "src"
},
{
"dir": "examples",
"type": "dev"
}
],
"package-specs": [
{
"module": "commonjs",
"in-source": true
}
],
"bs-dependencies": [
],
"bs-dev-dependencies": [
]
}
36 changes: 36 additions & 0 deletions examples/run.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
let bench =
Bench.make(~time=100.0, ())
->Bench.add("switch 1", () => {
let a = ref(1)
let b = ref(2)
let c = a.contents
a := b.contents
b := c
})
->Bench.add("switch 2", () => {
let a = ref(1)
let b = ref(10)
a := b.contents + a.contents
b := a.contents - b.contents
a := b.contents - a.contents
})

let run = async () => {
await bench.run(.)

open Belt
bench.tasks->Array.forEach(task => {
switch task {
| {name, result: Some(result)} => {
Js.log(`Task name: ${name}`)
Js.log(`Average Time (ps): ${Float.toString(result.mean *. 1000.)}`)
Js.log(`Variance (ps): ${Float.toString(result.variance *. 1000.)}`)
Js.log("")
}

| {name} => Js.log(`Error occured while running bench ${name}`)
}
})
}

run()->ignore
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "rescript-tinybench",
"description": "ReScript bidnings to tinybench",
"version": "1.0.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/cometkim/rescript-tinybench.git"
},
"author": {
"name": "Hyeseong Kim",
"email": "hey@hyeseong.kim"
},
"keywords": [
"rescript",
"rescript-bindings",
"benchmark"
],
"packageManager": "yarn@3.3.1",
"files": [
"bsconfig.json",
"src/*.res"
],
"peerDependencies": {
"rescript": "^10.1.0"
},
"dependencies": {
"tinybench": "^2.3.1"
},
"devDependencies": {
"rescript": "^10.1.0"
}
}
37 changes: 37 additions & 0 deletions src/Bench.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
type t = {
run: (. unit) => Js.Promise2.t<unit>,
tasks: array<Task.t>,
}

type options

%%private(
@obj
external makeOptions: (
~time: option<float>=?,
~iterations: option<int>=?,
~now: option<unit => float>=?,
~warmupTime: option<float>=?,
~warmupIterations: option<int>=?,
unit,
) => options = ""

@new @module("tinybench")
external make: options => t = "Bench"
)

let make = (~time=?, ~iterations=?, ~now=?, ~warmupTime=?, ~warmupIterations=?, ()) => {
makeOptions(~time, ~iterations, ~now, ~warmupTime, ~warmupIterations, ())->make
}

@send
external add: (t, string, unit => unit) => t = "add"

@send
external addAsync: (t, string, unit => Js.Promise2.t<unit>) => t = "add"

@send
external run: t => Js.Promise.t<unit> = "run"

@get
external tasks: t => array<Task.t> = "tasks"
36 changes: 36 additions & 0 deletions src/Task.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
type result = {
error: option<{.}>,
totalTime: float,
min: float,
max: float,
hz: float,
period: float,
samples: array<float>,
mean: float,
variance: float,
sd: float,
sem: float,
df: float,
critical: float,
moe: float,
rme: float,
p75: float,
p99: float,
p995: float,
p999: float,
}

type t = {
name: string,
result: option<result>,
}

type fn = unit => unit

@get
external getFn: t => fn = "fn"

type asyncFn = unit => Js.Promise2.t<unit>

@get
external getAsyncFn: t => asyncFn = "fn"
36 changes: 36 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 6
cacheKey: 8

"rescript-tinybench@workspace:.":
version: 0.0.0-use.local
resolution: "rescript-tinybench@workspace:."
dependencies:
rescript: ^10.1.0
tinybench: ^2.3.1
peerDependencies:
rescript: ^10.1.0
languageName: unknown
linkType: soft

"rescript@npm:^10.1.0":
version: 10.1.0
resolution: "rescript@npm:10.1.0"
bin:
bsc: bsc
bsrefmt: bsrefmt
bstracing: lib/bstracing
rescript: rescript
checksum: b0b6ffbe7e6fc52098ccdeea30dff886dff4cf09c8cd85bdfa2b6cd7a854f35c167aa96e03f1590070315c344b85f24f311aa8ac26d3e96a763730a03bb99d7d
languageName: node
linkType: hard

"tinybench@npm:^2.3.1":
version: 2.3.1
resolution: "tinybench@npm:2.3.1"
checksum: 74d45fa546d964a8123f98847fc59550945ed7f0d3e5a4ce0f9596d836b51c1d340c2ae0277a8023c15dc9ea3d7cb948a79173bfc46338c9b367c6323ea1eaf3
languageName: node
linkType: hard

0 comments on commit 61d84ad

Please sign in to comment.