Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: eslint fix part 2 and optimize types style #3

Merged
merged 15 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json"
},
"plugins": [
"@typescript-eslint/eslint-plugin"
],
"extends": [
"airbnb-base",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended"
],
"root": true,
"env": {
"node": true,
"commonjs": true
},
"rules": {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-types": "off",
"import/no-unresolved": "off",
"import/extensions": "off",
"no-underscore-dangle": "off",
"indent": [
"error",
2
],
"max-len": 0
}
}
12 changes: 12 additions & 0 deletions .size-limit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"path": "dist/index.js",
"import": "{ createStore }",
"limit": "10 kB"
},
{
"path": "dist/index.cjs",
"import": "{ createStore }",
"limit": "10 kB"
}
]
188 changes: 188 additions & 0 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import Task from '../src/task';

declare global {
/**
* the task function
*/
export type Fn = () => any | Promise<any>;

/**
* the benchmark task result object
*/
export type ITaskResult = {
/*
* the last error that was thrown while running the task
*/
error?: unknown;

/**
* The amount of time in milliseconds to run the benchmark task (cycle).
*/
totalTime: number;

/**
* the minimum value in the samples
*/
min: number;
/**
* the maximum value in the samples
*/
max: number;

/**
* the number of operations per second
*/
hz: number;

/**
* how long each operation takes (ms)
*/
period: number;

/**
* task samples of each task iteration time (ms)
*/
samples: number[];

/**
* samples mean/average (estimate of the population mean)
*/
mean: number;

/**
* samples variance (estimate of the population variance)
*/
variance: number;

/**
* samples standard deviation (estimate of the population standard deviation)
*/
sd: number;

/**
* standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
*/
sem: number;

/**
* degrees of freedom
*/
df: number;

/**
* critical value of the samples
*/
critical: number;

/**
* margin of error
*/
moe: number;

/**
* relative margin of error
*/
rme: number;

/**
* p75 percentile
*/
p75: number;

/**
* p99 percentile
*/
p99: number;

/**
* p995 percentile
*/
p995: number;

/**
* p999 percentile
*/
p999: number;
};

/**
* Both the `Task` and `Bench` objects extend the `EventTarget` object,
* so you can attach a listeners to different types of events
* to each class instance using the universal `addEventListener` and
* `removeEventListener`
*/

/**
* Bench events
*/
export type IBenchEvents =
| 'abort' // when a signal aborts
| 'complete' // when running a benchmark finishes
| 'error' // when the benchmark task throws
| 'reset' // when the reset function gets called
| 'start' // when running the benchmarks gets started
| 'warmup' // when the benchmarks start getting warmed up (before start)
| 'cycle' // when running each benchmark task gets done (cycle)
| 'add' // when a Task gets added to the Bench
| 'remove'; // when a Task gets removed of the Bench

export type IHook = (task: Task, mode: 'warmup' | 'run') => void | Promise<void>;

/**
* task events
*/
export type ITaskEvents =
| 'abort'
| 'complete'
| 'error'
| 'reset'
| 'start'
| 'warmup'
| 'cycle';

export type IOptions = {
/**
* time needed for running a benchmark task (milliseconds) @default 500
*/
time?: number;

/**
* number of times that a task should run if even the time option is finished @default 10
*/
iterations?: number;

/**
* function to get the current timestamp in milliseconds
*/
now?: () => number;

/**
* An AbortSignal for aborting the benchmark
*/
signal?: AbortSignal;

/**
* warmup time (milliseconds) @default 100ms
*/
warmupTime?: number;

/**
* warmup iterations @default 5
*/
warmupIterations?: number;

/**
* setup function to run before each benchmark task (cycle)
*/
setup?: IHook;

/**
* teardown function to run after each benchmark task (cycle)
*/
teardown?: IHook;
};

export type IBenchEvent = Event & {
task: Task | null;
};
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ completely based on the Web APIs with proper timing using `process.hrtime` or

_In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an [RFC](https://github.com/tinylibs/rfcs)_

## Requirements
- node version >= v16

## Installing

```bash
Expand All @@ -27,7 +30,7 @@ You can start benchmarking by instantiating the `Bench` class and adding
benchmark tasks to it.

```ts
const { Bench } = require("tinybench");
const { Bench } = require('tinybench');
const bench = new Bench({ time: 100 });

bench
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,26 @@
"homepage": "https://github.com/tinylibs/tinyspy#readme",
"devDependencies": {
"@size-limit/preset-small-lib": "^7.0.4",
"@size-limit/time": "^7.0.4",
"@size-limit/time": "^7.0.8",
"@types/node": "^18.7.13",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/parser": "^5.35.1",
"bumpp": "^8.2.0",
"changelogithub": "^0.12.4",
"clean-publish": "^3.4.4",
"eslint": "^8.22.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"happy-dom": "^2.25.1",
"husky": "^7.0.4",
"nano-staged": "^0.5.0",
"prettier": "^2.5.1",
"size-limit": "^7.0.4",
"size-limit": "^8.0.1",
"tinyspy": "*",
"tsup": "^5.11.7",
"typescript": "^4.5.4",
"vite": "^2.9.12",
"vitest": "^0.14.2",
"changelogithub": "^0.6.5"
"vitest": "^0.14.2"
},
"keywords": [
"spy",
Expand All @@ -57,6 +62,6 @@
"method"
],
"engines": {
"node": ">=14.0.0"
"node": ">=16.0.0"
}
}
Loading