@as-tral/cli

中文文档
3.0.2发布于 2024/01/11ES Module近 30 天下载 2416

logo

原始使用文档
文档目录3 节
  1. Quickstart
  2. Suites (feature request)
  3. Flags

logo


Bringing minimalist, state-of-the-art benchmarking to AssemblyScript; as-tral is a port of the statistics-oriented Rust benchmarking library criterion.rs.

Quickstart

In an existing AssemblyScript project, install as-tral.

npm i -D @as-tral/cli

Next, create a __benches__ folder in your assembly directory. Add a file named as-tral.d.ts in there.

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

In as-tral.d.ts, copy and paste

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

Stick any file with a .ts extension in __benches__. You can even have multiple.

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

Your benchmark will live in this file. Let's create an example benchmark.

// 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(" "));
});

Now, let's run as-tral.

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

Pretty fast!

Suites (feature request)

Would you like extra output that looks like this?

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)

Simply group your benchmarks using suite.

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

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

    // ...
});

Flags

The CLI interprets all flags before -- as AssemblyScript compiler options. For example, to enable ESM bindings,

npx astral --bindings esm

If you also want to save to a certain baseline,

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

Loading from a certain baseline is similar.

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

版本与发布记录

@as-tral/cli 共发布 13 个版本,首次发布于 2022/05/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.2latest2024/01/112 年前
3.0.12024/01/102 年前
3.0.02024/01/092 年前
2.0.12023/08/143 年前
2.0.02022/12/123 年前
1.2.02022/09/194 年前

关于 @as-tral/cli 的常见问题

如何安装 @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 和提交记录判断。