summaryrefslogtreecommitdiff
path: root/std/testing
diff options
context:
space:
mode:
Diffstat (limited to 'std/testing')
-rw-r--r--std/testing/README.md93
-rw-r--r--std/testing/bench_test.ts1
2 files changed, 62 insertions, 32 deletions
diff --git a/std/testing/README.md b/std/testing/README.md
index 4a9249205..42ce49d5c 100644
--- a/std/testing/README.md
+++ b/std/testing/README.md
@@ -137,9 +137,20 @@ Deno.test("fails", async function (): Promise<void> {
});
```
-### Benching Usage
+## Benching
-Basic usage:
+With this module you can benchmark your code and get information on how is it
+performing.
+
+### Basic usage:
+
+Benchmarks can be registered using the `bench` function, where you can define a
+code, that should be benchmarked. `b.start()` has to be called at the start of
+the part you want to benchmark and `b.stop()` at the end of it, otherwise an
+error will be thrown.
+
+After that simply calling `runBenchmarks()` will benchmark all registered
+benchmarks and log the results in the commandline.
```ts
import { runBenchmarks, bench } from "https://deno.land/std/testing/bench.ts";
@@ -167,43 +178,63 @@ bench({
});
```
+Running specific benchmarks using regular expressions:
+
+```ts
+runBenchmarks({ only: /desired/, skip: /exceptions/ });
+```
+
+### Processing benchmark results
+
+`runBenchmarks()` returns a `Promise<BenchmarkRunResult>`, so you can process
+the benchmarking results yourself. It contains detailed results of each
+benchmark's run as `BenchmarkResult` s.
+
+```ts
+runBenchmarks()
+ .then((results: BenchmarkRunResult) => {
+ console.log(results);
+ })
+ .catch((error: Error) => {
+ // ... errors if benchmark was badly constructed
+ });
+```
+
+### Processing benchmarking progress
+
+`runBenchmarks()` accepts an optional progress handler callback function, so you
+can get information on the progress of the running benchmarking.
+
+Using `{ silent: true }` means you wont see the default progression logs in the
+commandline.
+
+```ts
+runBenchmarks({ silent: true }, (p: BenchmarkRunProgress) => {
+ // initial progress data
+ if (p.state === ProgressState.BenchmarkingStart) {
+ console.log(
+ `Starting benchmarking. Queued: ${p.queued.length}, filtered: ${p.filtered}`
+ );
+ }
+ // ...
+});
+```
+
#### Benching API
##### `bench(benchmark: BenchmarkDefinition | BenchmarkFunction): void`
Registers a benchmark that will be run once `runBenchmarks` is called.
-##### `runBenchmarks(opts?: BenchmarkRunOptions): Promise<void>`
+##### `runBenchmarks(opts?: BenchmarkRunOptions, progressCb?: (p: BenchmarkRunProgress) => void): Promise<BenchmarkRunResult>`
Runs all registered benchmarks serially. Filtering can be applied by setting
`BenchmarkRunOptions.only` and/or `BenchmarkRunOptions.skip` to regular
-expressions matching benchmark names.
+expressions matching benchmark names. Default progression logs can be turned off
+with the `BenchmarkRunOptions.silent` flag.
-##### Other exports
+##### `clearBenchmarks(opts?: BenchmarkClearOptions): void`
-```ts
-/** Provides methods for starting and stopping a benchmark clock. */
-export interface BenchmarkTimer {
- start: () => void;
- stop: () => void;
-}
-
-/** Defines a benchmark through a named function. */
-export interface BenchmarkFunction {
- (b: BenchmarkTimer): void | Promise<void>;
- name: string;
-}
-
-/** Defines a benchmark definition with configurable runs. */
-export interface BenchmarkDefinition {
- func: BenchmarkFunction;
- name: string;
- runs?: number;
-}
-
-/** Defines runBenchmark's run constraints by matching benchmark names. */
-export interface BenchmarkRunOptions {
- only?: RegExp;
- skip?: RegExp;
-}
-```
+Clears all registered benchmarks, so calling `runBenchmarks()` after it wont run
+them. Filtering can be applied by setting `BenchmarkRunOptions.only` and/or
+`BenchmarkRunOptions.skip` to regular expressions matching benchmark names.
diff --git a/std/testing/bench_test.ts b/std/testing/bench_test.ts
index 8e34b27a9..e36451fb0 100644
--- a/std/testing/bench_test.ts
+++ b/std/testing/bench_test.ts
@@ -237,7 +237,6 @@ test({
const benchingResults = await runBenchmarks(
{ skip: /skip/, silent: true },
(progress) => {
- // needs to be deep copied
progressCallbacks.push(progress);
}
);