deno.com

效能基準測試

在 Github 上編輯

在編寫函式庫時,一個非常常見的任務是測試方法的速度,通常是與其他函式庫比較。Deno 提供了一個易於使用的子命令來達到此目的。

deno 效能基準測試最基本的形式是提供一個名稱和一個要執行的匿名函式。
Deno.bench("URL parsing", () => {
  new URL("https://deno.land");
});
我們也可以使用 async 函式。
Deno.bench("Async method", async () => {
  await crypto.subtle.digest("SHA-256", new Uint8Array([1, 2, 3]));
});
我們可以選擇性地使用長格式效能基準測試定義。
Deno.bench({
  name: "Long form",
  fn: () => {
    new URL("https://deno.land");
  },
});
我們也可以使用選用的 group 和 baseline 引數將某些效能基準測試分組在一起。
Deno.bench({
  name: "Date.now()",
  group: "timing",
  baseline: true,
  fn: () => {
    Date.now();
  },
});

Deno.bench({
  name: "performance.now()",
  group: "timing",
  fn: () => {
    performance.now();
  },
});

您找到需要的資訊了嗎?

隱私權政策