Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yamiteru committed Apr 4, 2023
1 parent c32b229 commit 333fb3b
Showing 1 changed file with 35 additions and 47 deletions.
82 changes: 35 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You no longer have to ask yourself, "Is it fast?" Just benchmark it!
- Runs GC before every benchmark and suite for reduced memory noise.
- Uses high-resolution time in nanoseconds for more accurate CPU results.
- Exposes lifecycle events for real-time data monitoring.
- Prints colorful benchmark results in the terminal.
- Prints colorful benchmark results in the terminal (verbose/compact).
- Allows combining different output strategies (terminal/markdown/etc.).

## Installation
Expand All @@ -34,34 +34,36 @@ For the most accurate results, it is recommended to run benchmark suites in diff
## Example

```ts
import { createPreset, useTerminal } from "isitfast";

// define suite preset with options
const defaultSuite = createPreset();
import { suite, useTerminal } from "isitfast";

// define your suite with benchmarks
const testBenchmark = defaultSuite("Test", {
emptyAsync: async () => {},
emptySync: () => {},
});
const testBenchmark = suite("Test")
.add("emptyAsync", async () => {})
.add("emptySync", () => {});

(async () => {
// collect data and print them into a terminal
await useTerminal();
useTerminal();

// run all benchmarks and trigger lifecycle events
await testBenchmark();
await testBenchmark.run();
})();
```

## API
---

# API

### `createPreset`
## Suite

Creates a suite preset with the provided options.
You can create a `Suite` with by calling either `suite(name: string, options?: DeepPartial<Options>)` or `new Suite(name: string, options?: DeepPartial<Options>)`.

```ts
const suite = createPreset({
const testOne = suite("Test One", {
// options
});

const testTwo = new Suite("Test Two", {
// options
});
```
Expand All @@ -72,71 +74,57 @@ These are the default options:
{
cpu: {
chunkSize: 100,
compareSize: 10,
rangePercent: 10,
compareSize: 25,
rangePercent: 1,
},
ram: {
chunkSize: 5,
compareSize: 5,
rangePercent: 5,
rangePercent: 1,
},
offset: {
allow: true,
rangePercent: 5,
rangePercent: 1,
},
gc: {
allow: true,
}
}
```

### `createSuite`

Creates a named suite with an object of benchmarks.

Usually you get this `suite` function from calling `preset` with options. But if you want just a suite with default options then you can import `suite` function directly from the library.
## Modes

```ts
const firstSuite = suite("Name", {
// benchmarks
});
```
### `useTerminal`

Since all suites share the same references to internal objects you should never run multiple suites at the same time (not awaiting them). This is how multiple suites should be run:
Listens to events and prints verbose suite and benchmark results into a terminal.

```ts
await firstSuite();
await secondSuite();
await thirdSuite();
```

### `runSuite`

Collects stats for the previously defined benchmarks and triggers lifecycle events with the appropriate data.
// subscribe to events
useTerminal();

```ts
await firstSuite();
// run suite which publishes data to the events
await runBenchmarks.run();
```

### `useTerminal`
### `useTerminalCompact`

Listens to events and prints suite and benchmark results into a terminal.
Listens to events and prints compact suite and benchmark results into a terminal.

```ts
// subscribe to events
await useTerminal();
useTerminalCompact();

// run suite which publishes data to the events
await runBenchmarks();
await runBenchmarks.run();
```

## Events

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 `$`.
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 `$`.

Behind the scenes `isitfast` uses `ueve` to create, subscribe to and publish into events.
Behind the scenes `isitfast` uses [μEve](https://github.com/yamiteru/ueve) to create, subscribe to and publish into events.

You can easily import `sub`/`clr`/`has` event functions from `isitfast`. They're just re-exported functions from `ueve`.
You can easily import `sub`/`clr`/`has` event functions from `isitfast`. They're just re-exported functions from `μEve`.

- `$suiteBefore` Before suite gets run
- `$suiteOffsets` After suite offsets get calculated
Expand Down

0 comments on commit 333fb3b

Please sign in to comment.