TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Is it possible to do idempotent microbenchmarks?

1 点作者 adriansky将近 5 年前
Given a program with a fixed input and output. Is it possible to do a microbenchmark in an idempotent unit related to the work performed to compute the output?<p>In other words, If you run the same program multiple times with the same input, the benchmark should always result in the same value.<p>For instance, this node.js program. I want to run it multiple times and have the same benchmark value.<p><pre><code> &#x2F;&#x2F; Brute force: O(n^2) | O(1) function twoSum(nums, target) { for (let i = 0; i &lt; nums.length - 1; i++) { &#x2F;&#x2F; O(n^2) for (let j = i + 1; j &lt; nums.length; j++) { &#x2F;&#x2F; O(n) if (nums[i] + nums[j] === target) { return [i, j]; } } } return []; } console.log(twoSum(Array(1e7).fill(2), 4));</code></pre>

暂无评论

暂无评论