Skip to content

Commit f24315a

Browse files
committed
Split code into multiple packages
1 parent 1e90f5a commit f24315a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+807
-1559
lines changed
File renamed without changes.

README.md

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,117 @@
1-
# Isitfast monorepo
1+
# Isitfast
22

3-
- [isitfast](./packages/isitfast/README.md)
3+
A modular benchmarking library with V8 warmup and CPU/RAM denoising for the most accurate and consistent results.
4+
5+
You no longer have to ask yourself, "Is it fast?" Just benchmark it!
6+
7+
## Key Features
8+
9+
- Waits until V8 optimizations kick in and benchmarks become less noisy.
10+
- Eliminates performance noise caused by benchmark wrapper functions.
11+
- Reuses a couple of UInt32Arrays to store stats for reduced memory noise.
12+
- Runs GC before every benchmark and suite for reduced memory noise.
13+
- Uses high-resolution time in nanoseconds for more accurate CPU results.
14+
- Exposes lifecycle events for real-time data monitoring.
15+
- Prints colorful benchmark results in the terminal (verbose/compact).
16+
- Allows combining different output strategies (terminal/markdown/etc.).
17+
18+
## Installation
19+
20+
To install, run the following command in your terminal:
21+
22+
```shell
23+
yarn add isitfast
24+
```
25+
26+
## How to run
27+
28+
It is recommended to run isitfast with the --expose-gc Node flag to enable the library to run GC and collect more statistically correct memory data.
29+
30+
When used in a TypeScript environment, you can run it like this: node --expose-gc -r ts-node/register benchmarks/benchmarkName.ts.
31+
32+
For the most accurate results, it is recommended to run benchmark suites in different JS realms by putting them in separate files and executing them individually.
33+
34+
## Example
35+
36+
```ts
37+
import { Suite, useTerminal } from "isitfast";
38+
39+
// define your suite with benchmarks
40+
const testBenchmark = new Suite("Test")
41+
.add("emptyAsync", async () => {})
42+
.add("emptySync", () => {});
43+
44+
// collect data and print them into a terminal
45+
useTerminal();
46+
47+
// run all benchmarks and trigger lifecycle events
48+
testBenchmark.run();
49+
```
50+
51+
---
52+
53+
# API
54+
55+
## Suite
56+
57+
```ts
58+
const testTwo = new Suite("Test Two", {
59+
// options
60+
});
61+
```
62+
63+
These are the default options:
64+
65+
```ts
66+
{
67+
cpu: {
68+
chunkSize: 1_000,
69+
deviationPercent: 1,
70+
},
71+
ram: {
72+
chunkSize: 5,
73+
deviationPercent: 1,
74+
},
75+
offset: {
76+
allow: true,
77+
deviationPercent: 1,
78+
},
79+
gc: {
80+
allow: true,
81+
}
82+
}
83+
```
84+
85+
## Modes
86+
87+
### `useTerminal`
88+
89+
Listens to events and prints verbose suite and benchmark results into a terminal.
90+
91+
```ts
92+
// subscribe to events
93+
useTerminal();
94+
95+
// run suite which publishes data to the events
96+
runBenchmarks.run();
97+
```
98+
99+
### `useTerminalCompact`
100+
101+
Listens to events and prints compact suite and benchmark results into a terminal.
102+
103+
```ts
104+
// subscribe to events
105+
useTerminalCompact();
106+
107+
// run suite which publishes data to the events
108+
runBenchmarks.run();
109+
```
110+
111+
## Events
112+
113+
The `Suite` by itself doesn't return any data. For consuming suite and benchmarks data you should listen to events. All events are prefixed with `$`.
114+
115+
Behind the scenes `isitfast` uses [μEve](https://github.com/yamiteru/ueve) to create, subscribe to and publish into events.
116+
117+
You can easily import `sub`/`clr`/`has` event functions from `isitfast`. They're just re-exported functions from `μEve`.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"name": "isitfast",
3-
"version": "0.0.0",
4-
"private": true,
3+
"type": "module",
4+
"version": "0.0.8",
55
"workspaces": [
66
"packages/*"
77
],
88
"scripts": {
9-
"build": "turbo run build",
109
"fix:format": "prettier --write \"**/*.ts\"",
1110
"fix:lint": "eslint --fix --ext .ts .",
1211
"fix": "pnpm fix:lint && pnpm fix:format",
@@ -15,6 +14,7 @@
1514
"check": "pnpm check:lint && pnpm check:format"
1615
},
1716
"devDependencies": {
17+
"@types/node": "18.15.5",
1818
"@typescript-eslint/eslint-plugin": "5.56.0",
1919
"@typescript-eslint/parser": "5.56.0",
2020
"eslint": "8.37.0",

packages/constants/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": "0.0.0",
3+
"type": "module",
4+
"name": "@isitfast/constants",
5+
"main": "src/index.ts",
6+
"devDependencies": {
7+
"@isitfast/types": "workspace:*"
8+
}
9+
}

packages/isitfast/src/constants.ts renamed to packages/constants/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Either, Fn } from "elfs";
21
import {
32
Benchmarks,
43
Mode,
@@ -9,7 +8,9 @@ import {
98
Store,
109
Stores,
1110
Type,
12-
} from "./types";
11+
Fn,
12+
Either
13+
} from "@isitfast/types";
1314

1415
export const STATE: {
1516
name: string;
@@ -49,7 +50,7 @@ export const OFFSET_MIN: OffsetMin = {
4950
// Default options used in `preset`
5051
export const OPTIONS: Options = {
5152
cpu: {
52-
chunkSize: 1_000,
53+
chunkSize: 2_000,
5354
deviationPercent: 1,
5455
},
5556
ram: {

packages/events/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "0.0.0",
3+
"type": "module",
4+
"name": "@isitfast/events",
5+
"main": "src/index.ts",
6+
"devDependencies": {
7+
"@isitfast/types": "workspace:*"
8+
},
9+
"dependencies": {
10+
"ueve": "1.4.0"
11+
}
12+
}

packages/isitfast/src/events.ts renamed to packages/events/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { eve } from "ueve/async";
2-
import { Mode, Offset } from "./types";
2+
import { Mode, Offset } from "@isitfast/types";
33

44
export const $suiteStart = eve<{
55
suiteName: string;

packages/examples/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"type": "module",
3+
"name": "@isitfast/examples",
4+
"scripts": {
5+
"arrayLoops": "node --loader ts-node/esm src/arrayLoops.ts",
6+
"emptyFunctions": "node --loader ts-node/esm src/emptyFunctions.ts"
7+
},
8+
"dependencies": {
9+
"@isitfast/modes": "workspace:*",
10+
"@isitfast/suite": "workspace:*"
11+
},
12+
"devDependencies": {
13+
"@types/node": "18.15.5",
14+
"ts-node": "10.9.1",
15+
"typescript": "next"
16+
}
17+
}

packages/isitfast/examples/arrayLoops.ts renamed to packages/examples/src/arrayLoops.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { useTerminalCompact } from "../src";
2-
import { Suite } from "../src";
1+
import { Suite } from "@isitfast/suite";
2+
import { useTerminalVerbose } from "@isitfast/modes";
33

4-
const emptyFunctions = new Suite("Array loops")
4+
const arrayLoops = new Suite("Array loops")
55
.setup(() => ({
66
result: { _: 0 },
77
data: [...new Array(1_000)].map(() => Math.random() * 10),
@@ -27,6 +27,5 @@ const emptyFunctions = new Suite("Array loops")
2727
data.forEach((v) => (result._ = v));
2828
});
2929

30-
useTerminalCompact();
3130

32-
emptyFunctions.run();
31+
useTerminalVerbose(arrayLoops);

0 commit comments

Comments
 (0)