# @c4312/matcha 中文文档

规范地址：https://npmcn.com/package/%40c4312/matcha/

版本：1\.3\.1
npm 元数据更新时间：2022-04-04T21:25:22.999Z
中文译文更新时间：2026-11-08T22:41:51.054Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40c4312/matcha
原文对照：https://npmcn.com/package/%40c4312/matcha/?lang=original
项目主页：https://github.com/connor4312/matcha#readme
源码仓库：https://github.com/connor4312/matcha

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：69.6 kB，52 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：4 个
- 首次发布：2019-12-22T21:15:24.006Z
- 最新版本发布：2020-07-08T17:12:44.816Z
- 近 30 天下载量：5583（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 0 个）

## 中文简介

咖啡因驱动的简单基准命令行

## 安装

```sh
npm install @c4312/matcha
```

也可以使用：`pnpm add @c4312/matcha`、`yarn add @c4312/matcha`、`bun add @c4312/matcha`

## README

# @c4312/马查

现代化 [`matcha`](https://github.com/logicalparadox/matcha),由基准.js提供动力. 这些年我发现Matcha超级有用,但它已经 [准确的问题](https://github.com/logicalparadox/matcha/issues/22),不支持承诺 或与节点12, 而且显然被抛弃。 我们在这里解决!

![Demonstration video of the matcha command line](https://npmcn.com/package/%40c4312/matcha/demo.gif)

## 使用量

```
npm install --global @c4312/matcha
```

然后,你可以创建一个文件 `bench` 函数,例如: **我的本钱,js**数字 :

```js
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

bench('forEach', () => arr.forEach(v => (sum += v)));

bench('for-of loop', () => {
  for (const v of arr) {
    sum += v;
  }
});
```

然后,简单运行:

```
matcha my-bench.js
```

### 命令行选项

```
Usage: matcha [options] <file>

Options:
  -V, --version              output the version number
  -g, --grep <pattern>       Run a subset of benchmarks (default: "")
  -R, --reporter <reporter>  Specify the reporter to use (default: "pretty")
  --cpu-profile [pattern]    Run on all tests, or those matching the regex.
                             Saves a .cpuprofile file that can be opened in the Chrome devtools.
  --reporters                Display available reporters
  -h, --help                 output usage information
```

## 同步基准

你可以从基准返回承诺 并收回召回:

```js
bench('plain fs', callback => readFile(__filename, callback));
bench('promisifed fs', async () => await readFileAsync(__filename));
```

## 设置

您可以设置任何 [基准.js 选项](https://benchmarkjs.com/docs#options) 通过 `set()` 帮手 也可以采用Aync设置和撕裂方法.

```js
// in a promise:
set('setup', async () => {
  await waitUntilPageIsLoaded();
});

// or a callback:
set('teardown', callback => closePage(callback));

// as well as base options:
set('maxTime', 1);
set('minSamples', 2000);
```

## 嵌入式套装

多个基准套房可以被嵌入. 包括设置和拆卸在内的选项是继承的、被锁住和被推翻的.

```js
set('setup', globalPrepare);

// globalPrepare() run before:
bench('a', runA);

// globalPrepare() and nestedPrepare() run before
// these, and they run for 1 second at most:
suite('nested', () => {
  set('setup', nestedPrepare);
  set('maxTime', 1);
  bench('b', runB);
});
```

## API 密码

您可以在程序上使用 Matcha API :

```js
const { GatherReporter, benchmark } = require('@c4312/benchmark');

// A reporter that just stores results in an array:
const reporter = new GatherReporter();

await benchmark({
  reporter,
  prepare(api) {
    // The standard API as described above!
    api.bench('myFunction', fn);

    // This function may be async and return a promise,
    // which we'll wait for before we start benchmarking.
  },
});

for (const result of reporter.results) {
  console.log('Benchmark', result.name, 'runs at', result.hz, 'ops/sec');
}
```

## 常见问题

### @c4312/matcha 是什么？

咖啡因驱动的简单基准命令行

### 如何安装 @c4312/matcha？

在项目目录运行 npm install @c4312/matcha，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 matcha，可以用 npx matcha 直接运行。

### @c4312/matcha 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/c4312\_\_matcha 是否存在。

### @c4312/matcha 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @c4312/matcha 可以商用吗？

@c4312/matcha 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @c4312/matcha 的下载量有多少？

根据 npm 官方下载统计，@c4312/matcha 在 2026/10/09 – 2026/11/07 这 30 天内被下载 5,583 次，日均约 186 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @c4312/matcha 还在维护吗？

最新版本 1\.3\.1 发布于 2020/07/09（6 年前）；至今共发布 5 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/12/23。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

