summaryrefslogtreecommitdiff
path: root/cli/tsc/dts/lib.deno.ns.d.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2023-07-31 11:02:59 +0100
committerGitHub <noreply@github.com>2023-07-31 12:02:59 +0200
commit02865cb5a270b9a2229863e83582f2a8b5115b78 (patch)
tree56529bdc267d6779be2efb8c92e58119e3687f24 /cli/tsc/dts/lib.deno.ns.d.ts
parente348c11b64410cf91bd5925ffbc5a9009947a80f (diff)
feat(bench): add BenchContext::start() and BenchContext::end() (#18734)
Closes #17589. ```ts Deno.bench("foo", async (t) => { const resource = setup(); // not included in measurement t.start(); measuredOperation(resource); t.end(); resource.close(); // not included in measurement }); ```
Diffstat (limited to 'cli/tsc/dts/lib.deno.ns.d.ts')
-rw-r--r--cli/tsc/dts/lib.deno.ns.d.ts56
1 files changed, 49 insertions, 7 deletions
diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts
index cba6edb3b..1c8d9db63 100644
--- a/cli/tsc/dts/lib.deno.ns.d.ts
+++ b/cli/tsc/dts/lib.deno.ns.d.ts
@@ -996,13 +996,55 @@ declare namespace Deno {
): void;
/**
+ * Context that is passed to a benchmarked function. The instance is shared
+ * between iterations of the benchmark. Its methods can be used for example
+ * to override of the measured portion of the function.
+ *
+ * @category Testing
+ */
+ export interface BenchContext {
+ /** The current benchmark name. */
+ name: string;
+ /** The string URL of the current benchmark. */
+ origin: string;
+
+ /** Restarts the timer for the bench measurement. This should be called
+ * after doing setup work which should not be measured.
+ *
+ * ```ts
+ * Deno.bench("foo", async (t) => {
+ * const data = await Deno.readFile("data.txt");
+ * t.start();
+ * // some operation on `data`...
+ * });
+ * ```
+ */
+ start(): void;
+
+ /** End the timer early for the bench measurement. This should be called
+ * before doing teardown work which should not be measured.
+ *
+ * ```ts
+ * Deno.bench("foo", async (t) => {
+ * const file = await Deno.open("data.txt");
+ * t.start();
+ * // some operation on `file`...
+ * t.end();
+ * file.close();
+ * });
+ * ```
+ */
+ end(): void;
+ }
+
+ /**
* The interface for defining a benchmark test using {@linkcode Deno.bench}.
*
* @category Testing
*/
export interface BenchDefinition {
/** The test function which will be benchmarked. */
- fn: () => void | Promise<void>;
+ fn: (b: BenchContext) => void | Promise<void>;
/** The name of the test, which will be used in displaying the results. */
name: string;
/** If truthy, the benchmark test will be ignored/skipped. */
@@ -1073,7 +1115,7 @@ declare namespace Deno {
*
* @category Testing
*/
- export function bench(t: BenchDefinition): void;
+ export function bench(b: BenchDefinition): void;
/**
* Register a benchmark test which will be run when `deno bench` is used on
@@ -1100,7 +1142,7 @@ declare namespace Deno {
*/
export function bench(
name: string,
- fn: () => void | Promise<void>,
+ fn: (b: BenchContext) => void | Promise<void>,
): void;
/**
@@ -1126,7 +1168,7 @@ declare namespace Deno {
*
* @category Testing
*/
- export function bench(fn: () => void | Promise<void>): void;
+ export function bench(fn: (b: BenchContext) => void | Promise<void>): void;
/**
* Register a benchmark test which will be run when `deno bench` is used on
@@ -1162,7 +1204,7 @@ declare namespace Deno {
export function bench(
name: string,
options: Omit<BenchDefinition, "fn" | "name">,
- fn: () => void | Promise<void>,
+ fn: (b: BenchContext) => void | Promise<void>,
): void;
/**
@@ -1196,7 +1238,7 @@ declare namespace Deno {
*/
export function bench(
options: Omit<BenchDefinition, "fn">,
- fn: () => void | Promise<void>,
+ fn: (b: BenchContext) => void | Promise<void>,
): void;
/**
@@ -1230,7 +1272,7 @@ declare namespace Deno {
*/
export function bench(
options: Omit<BenchDefinition, "fn" | "name">,
- fn: () => void | Promise<void>,
+ fn: (b: BenchContext) => void | Promise<void>,
): void;
/** Exit the Deno process with optional exit code.