Skip to content

Commit

Permalink
docs: Benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Sep 5, 2021
1 parent d2befc8 commit 9986583
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 7 deletions.
90 changes: 90 additions & 0 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,96 @@ Show elements.
$show('#test');
```

## Benchmark

JavaScript Benchmark.

<details>
<summary>Type Definition</summary>
<pre>
<code class="language-typescript">namespace Benchmark {
interface IOptions {
minTime?: number;
maxTime?: number;
minSamples?: number;
delay?: number;
name?: string;
}
interface IResult {
name: string;
mean: number;
variance: number;
deviation: number;
sem: number;
moe: number;
rme: number;
hz: number;
sample: number[];
}
}
class Benchmark {
constructor(fn: types.anyFn, options?: Benchmark.IOptions);
run(): Promise&lt;Benchmark.IResult&gt;;
static all(
benches: Array&lt;types.anyFn | Benchmark&gt;,
options?: Benchmark.IOptions
): Promise;
}</code>
</pre>
</details>

### constructor

|Name |Desc |
|-------|----------------------|
|fn |Code for speed testing|
|options|Benchmark options |

Available options:

|Name |Desc |
|------------|----------------------------------|
|minTime=50 |Time needed to reduce uncertainty |
|maxTime=5000|Maximum time for running benchmark|
|minSamples=5|Minimum sample size |
|delay=5 |Delay between test cycles |
|name |Benchmark name |

### run

Run benchmark, returns a promise.

### all

[static] Run some benchmarks.

```javascript
const benchmark = new Benchmark(
function test() {
!!'Hello World!'.match(/o/);
},
{
maxTime: 1500
}
);
benchmark.run().then(result => {
console.log(String(result));
});
Benchmark.all([
function regExp() {
/o/.test('Hello World!');
},
function indexOf() {
'Hello World!'.indexOf('o') > -1;
},
function match() {
!!'Hello World!'.match(/o/);
}
]).then(results => {
console.log(String(results));
});
```

## Blob

Use Blob when available, otherwise BlobBuilder.
Expand Down
90 changes: 90 additions & 0 deletions DOC_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,96 @@ $safeEls('.test'); // -> Array of elements with test class
$show('#test');
```

## Benchmark

JavaScript 基准测试。

<details>
<summary>类型定义</summary>
<pre>
<code class="language-typescript">namespace Benchmark {
interface IOptions {
minTime?: number;
maxTime?: number;
minSamples?: number;
delay?: number;
name?: string;
}
interface IResult {
name: string;
mean: number;
variance: number;
deviation: number;
sem: number;
moe: number;
rme: number;
hz: number;
sample: number[];
}
}
class Benchmark {
constructor(fn: types.anyFn, options?: Benchmark.IOptions);
run(): Promise&lt;Benchmark.IResult&gt;;
static all(
benches: Array&lt;types.anyFn | Benchmark&gt;,
options?: Benchmark.IOptions
): Promise;
}</code>
</pre>
</details>

### constructor

|参数名|说明|
|-----|---|
|fn|要测试的代码|
|options|测试选项|

可用选项:

|参数名|说明|
|-----|---|
|minTime=50|用于减少误差的时间|
|maxTime=5000|测试运行最大时间|
|minSamples=5|最小样本数量|
|delay=5|测试周期间隔|
|name|测试名称|

### run

运行基准测试,返回 promise。

### all

[static] 运行多个基准测试。

```javascript
const benchmark = new Benchmark(
function test() {
!!'Hello World!'.match(/o/);
},
{
maxTime: 1500
}
);
benchmark.run().then(result => {
console.log(String(result));
});
Benchmark.all([
function regExp() {
/o/.test('Hello World!');
},
function indexOf() {
'Hello World!'.indexOf('o') > -1;
},
function match() {
!!'Hello World!'.match(/o/);
}
]).then(results => {
console.log(String(results));
});
```

## Blob

如果支持 Blob,直接返回 Blob,否则使用 BlobBuilder 进行兼容。
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"average",
"base64",
"before",
"Benchmark",
"binarySearch",
"bind",
"Blob",
Expand Down
1 change: 1 addition & 0 deletions eslint.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var globals = {
_: true,
util: true,
expect: true,
benchmark: true,
tests: true,
options: true,
LICIA_TEST: true
Expand Down
28 changes: 28 additions & 0 deletions i18n/Benchmark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## CN

JavaScript 基准测试。

### constructor

|参数名|说明|
|-----|---|
|fn|要测试的代码|
|options|测试选项|

可用选项:

|参数名|说明|
|-----|---|
|minTime=50|用于减少误差的时间|
|maxTime=5000|测试运行最大时间|
|minSamples=5|最小样本数量|
|delay=5|测试周期间隔|
|name|测试名称|

### run

运行基准测试,返回 promise。

### all

[static] 运行多个基准测试。
25 changes: 25 additions & 0 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,31 @@
"browser"
]
},
"Benchmark": {
"dependencies": [
"Class",
"defaults",
"Promise",
"perfNow",
"delay",
"average",
"reduce",
"each",
"map",
"table",
"toStr"
],
"description": "JavaScript Benchmark.",
"env": [
"node",
"browser",
"miniprogram"
],
"test": [
"node",
"browser"
]
},
"Blob": {
"dependencies": [
"root",
Expand Down
Loading

0 comments on commit 9986583

Please sign in to comment.