• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16declare class Benchmark {
17    static filter<T>(arr: T[], callback: (value: T) => any, thisArg?: any): T[];
18    static filter<T>(arr: T[], filter: string, thisArg?: any): T[];
19    static formatNumber(num: number): string;
20    static join(obj: Object, separator1?: string, separator2?: string): string;
21    static invoke(benches: Benchmark[], name: string | Object, ...args: any[]): any[];
22    static runInContext(context: Object): Function;
23
24    static each(obj: Object | any[], callback: Function, thisArg?: any): void;
25    static forEach<T>(arr: T[], callback: (value: T) => any, thisArg?: any): void;
26    static forOwn(obj: Object, callback: Function, thisArg?: any): void;
27    static has(obj: Object, path: any[] | string): boolean;
28    static indexOf<T>(arr: T[], value: T, fromIndex?: number): number;
29    static map<T, K>(arr: T[], callback: (value: T) => K, thisArg?: any): K[];
30    static reduce<T, K>(arr: T[], callback: (accumulator: K, value: T) => K, thisArg?: any): K;
31
32    static options: Benchmark.Options;
33    static platform: Benchmark.Platform;
34    static support: Benchmark.Support;
35    static version: string;
36
37    constructor(fn: Function | string, options?: Benchmark.Options);
38    constructor(name: string, fn: Function | string, options?: Benchmark.Options);
39    constructor(name: string, options?: Benchmark.Options);
40    constructor(options: Benchmark.Options);
41
42    id: number;
43    name?: string;
44    count: number;
45    cycles: number;
46    hz: number;
47    compiled: Function | string;
48    error: Error;
49    fn: Function | string;
50    aborted: boolean;
51    running: boolean;
52    setup: Function | string;
53    teardown: Function | string;
54
55    stats: Benchmark.Stats;
56    times: Benchmark.Times;
57
58    abort(): Benchmark;
59    clone(options: Benchmark.Options): Benchmark;
60    compare(benchmark: Benchmark): number;
61    emit(type: string | Object): any;
62    listeners(type: string): Function[];
63    off(type?: string, listener?: Function): Benchmark;
64    off(types: string[]): Benchmark;
65    on(type?: string, listener?: Function): Benchmark;
66    on(types: string[]): Benchmark;
67    reset(): Benchmark;
68    run(options?: Benchmark.Options): Benchmark;
69    toString(): string;
70}
71
72declare namespace Benchmark {
73    export interface Options {
74        async?: boolean | undefined;
75        defer?: boolean | undefined;
76        delay?: number | undefined;
77        id?: string | undefined;
78        initCount?: number | undefined;
79        maxTime?: number | undefined;
80        minSamples?: number | undefined;
81        minTime?: number | undefined;
82        name?: string | undefined;
83        onAbort?: Function | undefined;
84        onComplete?: Function | undefined;
85        onCycle?: Function | undefined;
86        onError?: Function | undefined;
87        onReset?: Function | undefined;
88        onStart?: Function | undefined;
89        setup?: Function | string | undefined;
90        teardown?: Function | string | undefined;
91        fn?: Function | string | undefined;
92        queued?: boolean | undefined;
93    }
94
95    export interface Platform {
96        description: string;
97        layout: string;
98        product: string;
99        name: string;
100        manufacturer: string;
101        os: string;
102        prerelease: string;
103        version: string;
104        toString(): string;
105    }
106
107    export interface Support {
108        browser: boolean;
109        timeout: boolean;
110        decompilation: boolean;
111    }
112
113    export interface Stats {
114        moe: number;
115        rme: number;
116        sem: number;
117        deviation: number;
118        mean: number;
119        sample: any[];
120        variance: number;
121    }
122
123    export interface Times {
124        cycle: number;
125        elapsed: number;
126        period: number;
127        timeStamp: number;
128    }
129
130    export class Deferred {
131        constructor(clone: Benchmark);
132
133        benchmark: Benchmark;
134        cycles: number;
135        elapsed: number;
136        timeStamp: number;
137
138        resolve(): void;
139    }
140
141    export interface Target {
142        options: Options;
143        async?: boolean | undefined;
144        defer?: boolean | undefined;
145        delay?: number | undefined;
146        initCount?: number | undefined;
147        maxTime?: number | undefined;
148        minSamples?: number | undefined;
149        minTime?: number | undefined;
150        name?: string | undefined;
151        fn?: Function | undefined;
152        id: number;
153        stats?: Stats | undefined;
154        times?: Times | undefined;
155        running: boolean;
156        count?: number | undefined;
157        compiled?: Function | undefined;
158        cycles?: number | undefined;
159        hz?: number | undefined;
160    }
161
162    export class Event {
163        constructor(type: string | Object);
164
165        aborted: boolean;
166        cancelled: boolean;
167        currentTarget: Object;
168        result: any;
169        target: Target;
170        timeStamp: number;
171        type: string;
172    }
173
174    export class Suite {
175        static options: { name: string };
176
177        constructor(name?: string, options?: Options);
178        constructor(options?: Options);
179
180        length: number;
181        aborted: boolean;
182        running: boolean;
183        name?: string;
184
185        abort(): Suite;
186        add(name: string, fn: Function | string, options?: Options): Suite;
187        add(fn: Function | string, options?: Options): Suite;
188        add(name: string, options?: Options): Suite;
189        add(options: Options): Suite;
190        clone(options: Options): Suite;
191        emit(type: string | Object): any;
192        filter(callback: Function | string): Suite;
193        join(separator?: string): string;
194        listeners(type: string): Function[];
195        off(type?: string, callback?: Function): Suite;
196        off(types: string[]): Suite;
197        on(type?: string, callback?: Function): Suite;
198        on(types: string[]): Suite;
199        push(benchmark: Benchmark): number;
200        reset(): Suite;
201        run(options?: Options): Suite;
202        reverse(): any[];
203        sort(compareFn: (a: any, b: any) => number): any[];
204        splice(start: number, deleteCount?: number): any[];
205        unshift(benchmark: Benchmark): number;
206
207        each(callback: Function): Suite;
208        forEach(callback: Function): Suite;
209        indexOf(value: any): number;
210        map(callback: Function | string): any[];
211        reduce<T>(callback: Function, accumulator: T): T;
212
213        pop(): Function;
214        shift(): Benchmark;
215        slice(start: number, end: number): any[];
216        slice(start: number, deleteCount: number, ...values: any[]): any[];
217    }
218}
219
220export = Benchmark;
221