perf!: allow reducing data retention, by adding `retainSamples` optio… · tinylibs/tinybench@572d9b6

Original file line numberDiff line numberDiff line change

@@ -157,6 +157,28 @@ bench.concurrency = 'task' // The concurrency mode to determine how tasks are ru

157157

await bench.run()

158158

```

159159
160+

## Retaining Samples

161+
162+

By default Tinybench does not keep the samples for `latency` and `throughput` to

163+

minimize memory usage. Enable sample retention if you need the raw samples for

164+

plotting, custom analysis, or exporting results.

165+
166+

You can enable samples retention at the bench level by setting the

167+

`retainSamples` option to `true` when creating a `Bench` instance:

168+
169+

```ts

170+

const bench = new Bench({ retainSamples: true })

171+

```

172+
173+

You can also enable samples retention by setting the `retainSamples` option to

174+

`true` when adding a task:

175+
176+

```ts

177+

bench.add('task with samples', () => {

178+

// Task logic here

179+

}, { retainSamples: true })

180+

```

181+
160182

## Aborting Benchmarks

161183
162184

Tinybench supports aborting benchmarks using `AbortSignal` at both the bench and task levels: