为AssemblyScript提供最低限度、最先进的基准;As-tral是面向统计的Rust基准图书馆的一端 标准.
快速启动
在现有的 AssemblyScript 项目, 安装为三角形.
npm i -D @as-tral/cli
下一个,创建一个 __benches__ 在您的文件夹中 assembly 目录。 添加名为的文件 as-tral.d.ts 在那边.
assembly/
└── __benches__/
└── as-tral.d.ts
单位 as-tral.d.ts复制和粘贴
/// <reference types="@as-tral/cli/as-tral" />
粘贴任何文件 .ts 扩展 __benches__你甚至可以拥有多个.
assembly/
└── __benches__/
├── as-tral.d.ts
└── my-benchmark.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
相当快!
诉讼 (专题请求)
需要额外输出吗?
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。 。 。 .
suite("sort", () => {
bench("bubble sort", () => {
bubbleSort();
});
bench("insertion sort", () => {
insertionSort();
});
// ...
});
旗帜
CLI之前会解释所有的旗帜 -- 作为 AssemblyScript 编译器选项. 例如,为了使无害环境管理具有约束力,
npx astral --bindings esm
如果你还想要保存到某个基线,
npx astral --bindings esm -- --save-baseline mybaseline
从某个基准装入类似.
npx astral --bindings esm -- --save-baseline mybaseline --baseline myotherbaseline