Skip to content

Instantly share code, notes, and snippets.

@QQBoxy
Created November 29, 2022 07:04
Show Gist options
  • Save QQBoxy/35a3abba99a17d9b33fdc8974055b706 to your computer and use it in GitHub Desktop.
Save QQBoxy/35a3abba99a17d9b33fdc8974055b706 to your computer and use it in GitHub Desktop.
前後端測時間效率
const { performance } = require('perf_hooks');
// 前端為 `window.performance`
// 後端為 `const { performance } = require('perf_hooks');`
const func = (n) => {
return ((1 + n) * n) / 2;
};
const start = performance.now();
func(1000000);
const end = performance.now();
console.log("milliseconds:", end - start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment