Skip to content

Commit

Permalink
Format and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yamiteru committed Apr 3, 2023
1 parent 93613f6 commit c32b229
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 116 deletions.
32 changes: 18 additions & 14 deletions src/modes/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ let benchmarkStart: Either<[null, Noop]> = null;
let benchmarkEnd: Either<[null, Noop]> = null;

/**
* Listens to events and prints suite and benchmark results into a terminal.
*
* @example
* ```ts
* // subscribe to events
* await useTerminal();
*
* // run suite which publishes data to the events
* await runBenchmarks();
* ```
* */
* Listens to events and prints suite and benchmark results into a terminal.
*
* @example
* ```ts
* // subscribe to events
* await useTerminal();
*
* // run suite which publishes data to the events
* await runBenchmarks();
* ```
* */
export async function useTerminal() {
let results: { name: string; cpu: Offset; ram: Offset }[] = [];
let longestBenchmarkName = 0;
Expand Down Expand Up @@ -98,9 +98,13 @@ export async function useTerminal() {
const cpuSecondaryInfo = gray(
`[-${cpuMin}, +${cpuMax}]% (${cpuCycles} cycles)`,
);
const cpuTime = gray(`(${cpu.median < 1_000_000
? `${cpu.median.toLocaleString()} ns`
: `${(cpu.median / 1_000_000).toPrecision(3)} ms`})`);
const cpuTime = gray(
`(${
cpu.median < 1_000_000
? `${cpu.median.toLocaleString()} ns`
: `${(cpu.median / 1_000_000).toPrecision(3)} ms`
})`,
);
const ramSecondaryInfo = gray(
`[-${ramMin}, +${ramMax}]% (${ramCycles} cycles)`,
);
Expand Down
7 changes: 1 addition & 6 deletions src/offset/getOffset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
FN_ASYNC,
FN_SYNC,
OFFSET,
OFFSETS,
} from "../constants";
import { FN_ASYNC, FN_SYNC, OFFSET, OFFSETS } from "../constants";
import { stats } from "../stats";
import { Name, TypeMode } from "../types";

Expand Down
140 changes: 70 additions & 70 deletions src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,88 +14,88 @@ import {
import { pub } from "ueve/async";

/**
* Creates a suite preset with the provided options
*
* @example
*
* ```ts
* const suite = preset({
* // options
* });
* ```
*
* These are the default options:
*
* ```ts
* {
* cpu: {
* chunkSize: 100,
* compareSize: 10,
* rangePercent: 10,
* },
* ram: {
* chunkSize: 5,
* compareSize: 5,
* rangePercent: 5,
* },
* offset: {
* allow: true,
* rangePercent: 5,
* },
* gc: {
* allow: true,
* }
* }
* ```
* */
* Creates a suite preset with the provided options
*
* @example
*
* ```ts
* const suite = preset({
* // options
* });
* ```
*
* These are the default options:
*
* ```ts
* {
* cpu: {
* chunkSize: 100,
* compareSize: 10,
* rangePercent: 10,
* },
* ram: {
* chunkSize: 5,
* compareSize: 5,
* rangePercent: 5,
* },
* offset: {
* allow: true,
* rangePercent: 5,
* },
* gc: {
* allow: true,
* }
* }
* ```
* */
export function createPreset(partialOptions?: DeepPartial<Options>) {
const options = getOptions(partialOptions);
const stores = createStores(options);

/**
* 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.
*
* @example
*
* ```ts
* const firstSuite = suite("Name", {
* // benchmarks
* });
* ```
*
* 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:
*
* @example
*
* ```ts
* await firstSuite();
* await secondSuite();
* await thirdSuite();
* ```
* */
* 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.
*
* @example
*
* ```ts
* const firstSuite = suite("Name", {
* // benchmarks
* });
* ```
*
* 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:
*
* @example
*
* ```ts
* await firstSuite();
* await secondSuite();
* await thirdSuite();
* ```
* */
return function createSuite<$Benchmarks extends Benchmarks>(
suiteName: string,
benchmarks: $Benchmarks,
) {
const suite = [Symbol(), suiteName] as Name;

/**
* Collects stats for the previously defined benchmarks
* and triggers lifecycle events with the appropriate data.
*
* @example
*
* ```ts
* await firstSuite();
* ```
* */
* Collects stats for the previously defined benchmarks
* and triggers lifecycle events with the appropriate data.
*
* @example
*
* ```ts
* await firstSuite();
* ```
* */
return async function runSuite() {
await pub($suiteBefore, { suite, benchmarks: Object.keys(benchmarks) });

Expand Down
28 changes: 14 additions & 14 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { $benchmarkAfterEach, $benchmarkBeforeEach } from "./events";
import { Name, RunData } from "./types";

/**
* @internal
*
* Runs cpu-async/cpu-sync/ram-async/ram-sync benchmark
* and triggers $benchmarkBeforeAll/$benchmarkAfterAll events.
*
* @example
*
* ```ts
* await run(benchmarkName, {
* benchmark,
* mode: "cpu",
* type: "async",
* });
* */
* @internal
*
* Runs cpu-async/cpu-sync/ram-async/ram-sync benchmark
* and triggers $benchmarkBeforeAll/$benchmarkAfterAll events.
*
* @example
*
* ```ts
* await run(benchmarkName, {
* benchmark,
* mode: "cpu",
* type: "async",
* });
* */
export async function run(name: Name, { benchmark, mode, type }: RunData) {
const isAsync = type === "async";
const store = GLOBAL.stores[mode].chunk;
Expand Down
24 changes: 12 additions & 12 deletions src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { run } from "./run";
import { Benchmark, Mode, Name, Offsets } from "./types";

/**
* @internal
*
* Runs benchmark in a loop until the difference between
* the maximum and minimum values of the last N values
* is less than the specified percentage.
*
* @example
*
* ```ts
* await stats(benchmarkName, benchmark, "cpu", offsets);
* ```
* */
* @internal
*
* Runs benchmark in a loop until the difference between
* the maximum and minimum values of the last N values
* is less than the specified percentage.
*
* @example
*
* ```ts
* await stats(benchmarkName, benchmark, "cpu", offsets);
* ```
* */
export async function stats(
name: Name,
benchmark: Benchmark,
Expand Down

0 comments on commit c32b229

Please sign in to comment.