Skip to content

Commit

Permalink
ADD: streamLog built-in processor
Browse files Browse the repository at this point in the history
  • Loading branch information
Llorx committed Aug 20, 2023
1 parent eeba2e2 commit 7441c92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ Returns the IsoBench instance, to concatenate new tests easily.
```typescript
bench.add<T>(name:string, test:(setupReturn:T)=>void, setup:()=>T):this;
```
Adds new test.
Adds new test with an isolated setup callback.
- `name`: The name of this test.
- `test`: The test function to run.
- `setup`: The setup function to run before the test.
If you are very concerned about the pollution between tests when preparing data that only one test needs, you can use the `setup` callback to return the data that will be provided to the `test` callback as the first argument. The other tests will not run this `setup` callback in their isolated processes. Example:
- `setup`: The setup function to run before the test. If you are very concerned about the pollution between tests when preparing data that only one test needs, you can use the `setup` callback to return the data that will be provided to the `test` callback as the first argument. The other tests will not run this `setup` callback in their isolated processes.

Example:
```typescript
bench.add("object.result", (obj) => {
// Test callback receiving the obj from the setup callback
Expand All @@ -168,6 +169,12 @@ bench.consoleLog():this;
```
Adds a built-in [Processor](#i-processor) that outputs the result in the console. Returns the IsoBench instance.

---
```typescript
bench.streamLog(stream:Stream.Writable):this;
```
Adds a built-in [Processor](#i-processor) that outputs the result in a writable stream, like a file or a socket. Returns the IsoBench instance.

---
```typescript
bench.addProcessor(processor:Processor):this;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iso-bench",
"version": "2.4.1",
"version": "2.4.2",
"description": "Small benchmark library focused in avoiding optimization/deoptimization pollution between tests by isolating them.",
"types": "./lib/_types/index.d.ts",
"main": "./lib/",
Expand Down
6 changes: 5 additions & 1 deletion src/IsoBench.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import FS from "fs";
import STREAM from "stream";

import { RunMessage, Test } from "./Test";
import { WorkerSetup, SetupMessage } from "./WorkerSetup";
import { Processor } from "./Processor";
import { ConsoleLog } from "./processors";
import { ConsoleLog, StreamLog } from "./processors";

let IDs = 0;
function getUniqueName(name:string, map:Map<string, unknown>) {
Expand Down Expand Up @@ -54,6 +55,9 @@ export class IsoBench {
consoleLog() {
return this.addProcessor(new ConsoleLog());
}
streamLog(stream:STREAM.Writable) {
return this.addProcessor(new StreamLog(stream));
}
async run() {
if (WorkerSetup) {
// If is a fork, try to run the specific test
Expand Down

0 comments on commit 7441c92

Please sign in to comment.