Skip to content

Commit

Permalink
Add tinybench to run benchmarks in Fantom (facebook#48453)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#48453

Changelog: [internal]

Adds tinybench 3.1.0 (which has support for sync execution) and defined Flow types for the package.

Reviewed By: dmytrorykun

Differential Revision: D66698545

fbshipit-source-id: faf44add74e5711ac0d50794ce3360eedc45f0a5
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jan 6, 2025
1 parent bc3072e commit 96205dd
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
121 changes: 121 additions & 0 deletions flow-typed/npm/tinybench_v3.1.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
* @oncall react_native
*/

declare module 'tinybench' {
declare export class Task extends EventTarget {
name: string;
result: void | $ReadOnly<TaskResult>;
runs: number;

reset(): void;
run(): Promise<Task>;
runSync(): Task;
warmup(): Promise<void>;
}

export type Hook = (
task: Task,
mode: 'run' | 'warmup',
) => Promise<void> | void;

export type BenchOptions = {
iterations?: number,
name?: string,
now?: () => number,
setup?: Hook,
signal?: AbortSignal,
teardown?: Hook,
throws?: boolean,
time?: number,
warmup?: boolean,
warmupIterations?: number,
warmupTime?: number,
};

export interface Statistics {
aad: void | number;
critical: number;
df: number;
mad: void | number;
max: number;
mean: number;
min: number;
moe: number;
p50: void | number;
p75: void | number;
p99: void | number;
p995: void | number;
p999: void | number;
rme: number;
samples: number[];
sd: number;
sem: number;
variance: number;
}

export interface TaskResult {
critical: number;
df: number;
error?: Error;
hz: number;
latency: Statistics;
max: number;
mean: number;
min: number;
moe: number;
p75: number;
p99: number;
p995: number;
p999: number;
period: number;
rme: number;
samples: number[];
sd: number;
sem: number;
throughput: Statistics;
totalTime: number;
variance: number;
}

export type FnOptions = {
afterAll?: (this: Task) => void | Promise<void>,
afterEach?: (this: Task) => void | Promise<void>,
beforeAll?: (this: Task) => void | Promise<void>,
beforeEach?: (this: Task) => void | Promise<void>,
};

export type Fn = () => Promise<mixed> | mixed;

declare export class Bench extends EventTarget {
concurrency: null | 'task' | 'bench';
name?: string;
opts: $ReadOnly<BenchOptions>;
threshold: number;

constructor(options?: BenchOptions): this;

// $FlowExpectedError[unsafe-getters-setters]
get results(): Array<$ReadOnly<TaskResult>>;

// $FlowExpectedError[unsafe-getters-setters]
get tasks(): Array<Task>;

add(name: string, fn: Fn, fnOpts?: FnOptions): this;
getTask(name: string): void | Task;
remove(name: string): this;
reset(): void;
run(): Promise<Array<Task>>;
runSync(): Array<Task>;
table(
convert?: (task: Task) => Record<string, void | string | number>,
): void | Array<Record<string, void | string | number>>;
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"shelljs": "^0.8.5",
"signedsource": "^1.0.0",
"supports-color": "^7.1.0",
"tinybench": "^3.1.0",
"typescript": "5.0.4",
"ws": "^6.2.3"
},
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8348,6 +8348,11 @@ tiny-invariant@^1.3.3:
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.3.tgz#46680b7a873a0d5d10005995eb90a70d74d60127"
integrity sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==

tinybench@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/tinybench/-/tinybench-3.1.0.tgz#ec68451ff05233cf3de12c46f39f06011897109a"
integrity sha512-Km+oMh2xqNCxuyoUsqbRmHgFSd8sATh7v7xreP+kHN6x67w28Pawr83WmBxcaORvxkc0Ex6zgqK951yBnTFaaQ==

tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
Expand Down

0 comments on commit 96205dd

Please sign in to comment.