Skip to main content

基准

基准

¥Benchmarking

如果你想要衡量更改如何影响应用的性能,则基准测试非常重要。我们提供了一种从用户和贡献者的角度对你的应用进行基准测试的简单方法。该设置允许你在不同分支和不同 Node.js 版本上自动执行基准测试。

¥Benchmarking is important if you want to measure how a change can affect the performance of your application. We provide a simple way to benchmark your application from the point of view of a user and contributor. The setup allows you to automate benchmarks in different branches and on different Node.js versions.

我们将使用的模块:

¥The modules we will use:

  • Autocannon:用 Node.js 编写的 HTTP/1.1 基准测试工具。

    ¥Autocannon: A HTTP/1.1 benchmarking tool written in node.

  • 分支比较器:检查多个 git 分支,执行脚本并记录结果。

    ¥Branch-comparer: Checkout multiple git branches, execute scripts and log the results.

  • Concurrently:同时运行命令。

    ¥Concurrently: Run commands concurrently.

  • Npx:NPM 包运行程序用于针对不同 Node.js 版本运行脚本并执行本地二进制文件。随 npm@5.2.0 一起发布。

    ¥Npx: NPM package runner used to run scripts against different Node.js Versions and execute local binaries. Shipped with npm@5.2.0.

简单

¥Simple

在当前分支中运行测试

¥Run the test in the current branch

npm run benchmark

针对不同的 Node.js 版本运行测试 ✨

¥Run the test against different Node.js versions ✨

npx -p node@10 -- npm run benchmark

高级

¥Advanced

在不同的分支中运行测试

¥Run the test in different branches

branchcmp --rounds 2 --script "npm run benchmark"

针对不同的 Node.js 版本在不同的分支中运行测试 ✨

¥Run the test in different branches against different Node.js versions ✨

branchcmp --rounds 2 --script "npm run benchmark"

将当前分支与主分支进行比较 (Gitflow)

¥Compare current branch with main (Gitflow)

branchcmp --rounds 2 --gitflow --script "npm run benchmark"

or

npm run bench

运行不同的示例

¥Run different examples

branchcmp --rounds 2 -s "node ./node_modules/concurrently -k -s first \"node ./examples/asyncawait.js\" \"node ./node_modules/autocannon -c 100 -d 5 -p 10 localhost:3000/\""