# @as-tral/cli 中文文档

规范地址：https://npmcn.com/package/%40as-tral/cli/

版本：3\.0\.2
npm 元数据更新时间：2024-01-11T00:28:45.215Z
中文译文更新时间：2026-11-06T22:01:03.673Z
软件包许可：未声明

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

原始 npm 页面：https://www.npmjs.com/package/%40as-tral/cli
原文对照：https://npmcn.com/package/%40as-tral/cli/?lang=original

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

- 包体积（解压后）：62.6 kB，11 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：5 个
- 首次发布：2022-05-07T20:14:34.792Z
- 最新版本发布：2024-01-11T00:28:45.037Z
- 近 30 天下载量：2416（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：13（近 12 个月 0 个）

## 中文简介

![logo](https://raw.githubusercontent.com/romdotdog/as-tral/main/as-tral.svg)

## 安装

```sh
npm install @as-tral/cli
```

也可以使用：`pnpm add @as-tral/cli`、`yarn add @as-tral/cli`、`bun add @as-tral/cli`

## README

![logo](https://raw.githubusercontent.com/romdotdog/as-tral/main/as-tral.svg)

* * *

为AssemblyScript提供最低限度、最先进的基准;As-tral是面向统计的Rust基准图书馆的一端 [标准.](https://github.com/bheisler/criterion.rs)

## 快速启动

在现有的 [AssemblyScript 项目,](https://www.assemblyscript.org/getting-started.html) 安装为三角形.

```
npm i -D @as-tral/cli
```

下一个,创建一个 `__benches__` 在您的文件夹中 `assembly` 目录。 添加名为的文件 `as-tral.d.ts` 在那边.

```
assembly/
└── __benches__/
    └── as-tral.d.ts
```

单位 `as-tral.d.ts`复制和粘贴

```xml
/// <reference types="@as-tral/cli/as-tral" />
```

粘贴任何文件 `.ts` 扩展 `__benches__`你甚至可以拥有多个.

```
assembly/
└── __benches__/
    ├── as-tral.d.ts
    └── my-benchmark.ts
```

您的基准将活在这个文件中 。 让我们建立一个实例基准.

```ts
// to ensure accurate benchmarks, we must make sure that binaryen doesn't do any sneaky
// optimizations on our input without us knowing. Thus, we must use `blackbox`.
const input = blackbox("The quick brown fox jumped over the lazy dog.".repeat(10));

// our string here must be a compile time constant.
// open an issue if you'd like to see this constraint lifted.
bench("string split", () => {
    // this function body will be run many times.
    // we must make sure our compiler won't throw away the computation,
    // so we use `blackbox` here again.
    blackbox(input.split(" "));
});
```

瞷иǐ.

```
rom@i9-cabin:~/demo$ npx astral
Compiling assembly/__benches__/hello.ts

Benchmarking string split: Warming up for 3000ms
Benchmarking string split: Collecting 100 samples in estimated 5018.6ms (1.2M iterations)
Benchmarking string split: Analyzing
string split            time: [3770.9ns 3775ns 3778.9ns]
Found 4 outliers among 100 measurements (4%)
  3 (3%) low mild
  1 (1%) high mild
```

相当快!

## 诉讼 [(专题请求)](https://github.com/romdotdog/as-tral/issues/3)

需要额外输出吗?

```
Relative to bubble sort
insertion sort          delta: [-39.704% -38.188% -36.807%] (p = 0.00 < 0.05)
selection sort          delta: [-70.733% -70.102% -69.483%] (p = 0.00 < 0.05)
merge sort              delta: [-81.935% -81.587% -81.226%] (p = 0.00 < 0.05)
quick sort              delta: [-91.517% -91.358% -91.201%] (p = 0.00 < 0.05)
```

简单地分组您使用的基准 `suite`。 。 。 .

```ts
suite("sort", () => {
    bench("bubble sort", () => {
        bubbleSort();
    });

    bench("insertion sort", () => {
        insertionSort();
    });

    // ...
});
```

## 旗帜

CLI之前会解释所有的旗帜 `--` 作为 [AssemblyScript 编译器选项.](https://www.assemblyscript.org/compiler.html#compiler-options) 例如,为了使无害环境管理具有约束力,

```
npx astral --bindings esm
```

如果你还想要保存到某个基线,

```
npx astral --bindings esm -- --save-baseline mybaseline
```

从某个基准装入类似.

```
npx astral --bindings esm -- --save-baseline mybaseline --baseline myotherbaseline
```

## 常见问题

### 如何安装 @as-tral/cli？

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

### @as-tral/cli 支持 TypeScript 吗？

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

### @as-tral/cli 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @as-tral/cli 可以商用吗？

@as-tral/cli 使用 未声明 许可。package\.json 没有声明许可证。没有许可证的代码默认保留全部权利，商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括，不构成法律意见，请以许可原文为准。

### @as-tral/cli 的下载量有多少？

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

### @as-tral/cli 还在维护吗？

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

