Skip to content

Commit 6400091

Browse files
committed
fix: benchmark
1 parent 8f934f0 commit 6400091

File tree

4 files changed

+66
-24
lines changed

4 files changed

+66
-24
lines changed

README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ The syntax of text/template can also be used for headings.
169169
- OS: macOS Monterey 12.6.3
170170
- CPU: Apple M1 Max
171171
- Memory: 64GB
172-
- Node.js: v20.11.1
173-
- pnpm: 8.1.1
172+
- Node.js: 20.11.1
173+
- npm: 10.5.1
174174

175-
We measured the time it took to generate a simple React component with each package. The benchmark project is available [here](./benchmarks)
175+
We measured the time it took to generate a simple React component with each package.
176+
The benchmark project is available [here](./benchmarks).
176177

177178
```tsx
178179
import React from "react";
@@ -182,11 +183,11 @@ export const {{ name }}: React.FC = (children: { children: React.ReactNode }) =>
182183

183184
### Result
184185

185-
| Package | Version | Time (ms) |
186-
| ------------ | ------- | --------- |
187-
| plop | 6.2.11 | 0.73 |
188-
| scaffdog | 3.0.0 | 0.16 |
189-
| **moldable** | latest | 0.05 |
186+
| Package | Version | Average time of 10 times(ms) |
187+
| ------------ | ------- | ---------------------------- |
188+
| plop | 6.2.11 | 0.233 |
189+
| scaffdog | 3.0.0 | 0.385 |
190+
| **moldable** | 0.0.4 | 0.182 |
190191

191192
Moldable is the fastest. This is because it is written in Go and executed by node after compiling it into a binary.
192193

@@ -196,6 +197,7 @@ Parts of the code from the following projects have been borrowed and modified fo
196197

197198
- [Plop.js(MIT License)](https://github.com/plopjs/plop/blob/b797aafa8ae90adb59462114412505f9ec0c5bb1/LICENSE.md)
198199
- [Scaffdog(MIT License)](https://github.com/scaffdog/scaffdog/blob/9221585670365f67f6c439aea33a09ca79ae499c/LICENSE)
200+
- [eslint-interactive(MIT License)](https://github.com/mizdra/eslint-interactive/blob/a5ab787c4ccc780a2999b88d59d719cd6c1e651d/LICENSE)
199201

200202
The list of licenses is available at [THIRD_PARTY_LICENSE](https://github.com/cyberagent-oss/moldable/blob/main/THIRD_PARTY_LICENSE.md).
201203

THIRD_PARTY_LICENSE.md

+28
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,31 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4343
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4444
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4545
THE SOFTWARE.
46+
47+
---
48+
49+
MIT License
50+
51+
Copyright (c) 2020 mizdra (owner of mizdra/eslint-interactive)
52+
Copyright (c) 2015 David Waterston (owner of davidwaterston/eslint-summary)
53+
Copyright (c) 2015 Omer Ganim (owner of ganimomer/eslint-stats)
54+
Copyright (c) 2015 Ian VanSchooten (owner of IanVS/eslint-stats)
55+
Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
56+
57+
Permission is hereby granted, free of charge, to any person obtaining a copy
58+
of this software and associated documentation files (the "Software"), to deal
59+
in the Software without restriction, including without limitation the rights
60+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61+
copies of the Software, and to permit persons to whom the Software is
62+
furnished to do so, subject to the following conditions:
63+
64+
The above copyright notice and this permission notice shall be included in all
65+
copies or substantial portions of the Software.
66+
67+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
73+
SOFTWARE.

benchmarks/benchmark.js

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
/**
2+
* Inspired by https://github.com/mizdra/eslint-interactive/blob/a5ab787c4ccc780a2999b88d59d719cd6c1e651d/e2e-test/global-installation/index.test.ts
3+
*/
14
"use strict";
25

36
const { spawn } = require("child_process");
47
const { rimraf } = require("rimraf");
58
const { mkdirp } = require("mkdirp");
69

710
const FILE_NAME = "for-benchmark";
11+
const MAX = 10;
812

913
const LF = String.fromCharCode(0x0a); // \n
1014
const DOWN = String.fromCharCode(0x1b, 0x5b, 0x42); // ↓
@@ -14,22 +18,12 @@ async function wait(ms) {
1418
return new Promise((resolve) => setTimeout(resolve, ms));
1519
}
1620

17-
async function readStream(stream) {
18-
let result = "";
19-
for await (const line of stream) {
20-
result += line;
21-
}
22-
return result;
23-
}
24-
2521
async function clear() {
2622
await rimraf("./src");
2723
await mkdirp("./src");
2824
}
2925

30-
(async () => {
31-
const type = process.argv[2];
32-
26+
async function bench(type) {
3327
if (type === "plop") {
3428
const plop = spawn("./node_modules/.bin/plop");
3529
await wait(1000);
@@ -38,7 +32,7 @@ async function clear() {
3832
const plopMeasureStart = performance.now();
3933
plop.stdin.write(LF);
4034
const plopMeasureEnd = performance.now();
41-
console.log(`plop: ${plopMeasureEnd - plopMeasureStart}ms`);
35+
return plopMeasureEnd - plopMeasureStart;
4236
}
4337

4438
if (type === "scaffdog") {
@@ -55,7 +49,7 @@ async function clear() {
5549
const scaffdogMeasureStart = performance.now();
5650
scaffdog.stdin.write(LF);
5751
const scaffdogMeasureEnd = performance.now();
58-
console.log(`scaffdog: ${scaffdogMeasureEnd - scaffdogMeasureStart}ms`);
52+
return scaffdogMeasureEnd - scaffdogMeasureStart;
5953
}
6054

6155
if (type === "moldable") {
@@ -68,8 +62,26 @@ async function clear() {
6862
const moldableMeasureStart = performance.now();
6963
moldable.stdin.write(LF);
7064
const moldableMeasureEnd = performance.now();
71-
console.log(`moldable: ${moldableMeasureEnd - moldableMeasureStart}ms`);
65+
return moldableMeasureEnd - moldableMeasureStart;
66+
}
67+
68+
return 0;
69+
}
70+
71+
(async () => {
72+
const type = process.argv[2];
73+
74+
const results = [];
75+
for (let i = 0; i < MAX; i++) {
76+
const result = await bench(type);
77+
console.log(`[${type}] ${i + 1} time: ${result}ms`);
78+
results.push(result);
79+
await clear();
7280
}
7381

74-
await clear();
82+
console.log(
83+
`[${type}] average time of 10 times: ${results.reduce((acc, cur) => acc + cur, 0) / MAX}ms`
84+
);
85+
86+
process.exit(0);
7587
})();

benchmarks/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"name": "benchmarks",
44
"scripts": {
5-
"bench": "run-p bench:*",
5+
"bench": "run-s bench:*",
66
"bench:plop": "node benchmark.js plop",
77
"bench:scaffdog": "node benchmark.js scaffdog",
88
"bench:moldable": "node benchmark.js moldable"

0 commit comments

Comments
 (0)