generated from yamiteru/ts-package
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite in OOP + add compact terminal mode
- Loading branch information
Showing
13 changed files
with
455 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,45 @@ | ||
import { eve } from "ueve/async"; | ||
import { Name, Offset, Offsets } from "./types"; | ||
import { Offset, Offsets } from "./types"; | ||
|
||
// Before suite gets run | ||
export const $suiteBefore = eve<{ suite: Name; benchmarks: string[] }>(); | ||
export const $suiteBefore = eve<{ | ||
suiteName: string; | ||
benchmarkNames: string[]; | ||
}>(); | ||
|
||
// After suite offsets get calculated | ||
export const $suiteOffsets = eve<{ | ||
suite: Name; | ||
suiteName: string; | ||
offsets: Offsets; | ||
}>(); | ||
|
||
// After suite gets run | ||
export const $suiteAfter = eve<{ suite: Name }>(); | ||
export const $suiteAfter = eve<{ suiteName: string }>(); | ||
|
||
// Before benchmark of one type gets run | ||
export const $benchmarkBeforeAll = eve<{ suite: Name; benchmark: Name }>(); | ||
export const $benchmarkBeforeAll = eve<{ | ||
suiteName: string; | ||
benchmarkName: string; | ||
}>(); | ||
|
||
// After benchmark of one type gets run | ||
export const $benchmarkAfterAll = eve<{ | ||
suite: Name; | ||
benchmark: Name; | ||
suiteName: string; | ||
benchmarkName: string; | ||
cpu: Offset; | ||
ram: Offset; | ||
}>(); | ||
|
||
// Before each benchmark of one type gets run | ||
export const $benchmarkBeforeEach = eve<{ benchmark: Name }>(); | ||
export const $benchmarkBeforeEach = eve<{ | ||
suiteName: string; | ||
benchmarkName: string; | ||
}>(); | ||
|
||
// After each benchmark of one type gets run | ||
export const $benchmarkAfterEach = eve<{ benchmark: Name }>(); | ||
export const $benchmarkAfterEach = eve<{ | ||
suiteName: string; | ||
benchmarkName: string; | ||
}>(); | ||
|
||
export { sub, clr, has } from "ueve/async"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from "./types"; | ||
export * from "./preset"; | ||
export * from "./suite"; | ||
export * from "./events"; | ||
export * from "./modes"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./terminal"; | ||
export * from "./terminalCompact"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { sub } from "ueve/async"; | ||
import { bold, gray, blue, cyan } from "chalk"; | ||
import { MS_IN_SECOND, TIME_UNIT, UNITS_IN_SECOND } from "../constants"; | ||
import { $benchmarkAfterAll } from "../events"; | ||
|
||
/** | ||
* Listens to events and prints suite and benchmark results into a terminal. | ||
* | ||
* @example | ||
* ```ts | ||
* // subscribe to events | ||
* useTerminalCompact(); | ||
* | ||
* // run suite which publishes data to the events | ||
* await testSuite.run(); | ||
* ``` | ||
* */ | ||
export function useTerminalCompact() { | ||
sub($benchmarkAfterAll, async ({ benchmarkName, cpu, ram }) => { | ||
const ops = ( | ||
cpu.median === 0 ? Infinity : Math.round(UNITS_IN_SECOND / cpu.median) | ||
).toLocaleString(); | ||
const cpuDeviation = cpu.deviation.toPrecision(1).toLocaleString(); | ||
const cpuCycles = cpu.cycles.toLocaleString(); | ||
const kb = Math.round(ram.median).toLocaleString(); | ||
const ramDeviation = ram.deviation.toPrecision(1).toLocaleString(); | ||
const ramCycles = ram.cycles.toLocaleString(); | ||
const cpuSecondaryInfo = gray(`±${cpuDeviation}% x${cpuCycles}`); | ||
const cpuTime = gray( | ||
`(${ | ||
TIME_UNIT === "ns" && cpu.median < 1_000_000 | ||
? `${cpu.median.toLocaleString()} ns` | ||
: `${(cpu.median / MS_IN_SECOND).toPrecision(3)} ms` | ||
})`, | ||
); | ||
const ramSecondaryInfo = gray(`±${ramDeviation}% x${ramCycles}`); | ||
|
||
console.log( | ||
`${bold(benchmarkName)} ${blue( | ||
ops, | ||
)} op/s ${cpuTime} ${cpuSecondaryInfo} | ${cyan( | ||
kb, | ||
)} kB ${ramSecondaryInfo}`, | ||
); | ||
}); | ||
} |
Oops, something went wrong.