【问题标题】:Benchmark path-planning algorithm written in TypeScript in the browser在浏览器中用 TypeScript 编写的基准路径规划算法
【发布时间】:2018-10-25 11:21:39
【问题描述】:

我有 3 种打字稿算法需要在浏览器中进行基准测试。我试过 area51,area51 只适用于 JavaScript。我还发现了一个pastebin:

//pastebin.com/gCs9CB5F

谁能告诉我如何在 TypeScript 上运行基准测试?

【问题讨论】:

  • 你能澄清一下你的问题吗?根本不清楚你在问什么。
  • 根据您使用的环境,您可以将打字稿编译成纯 javascript,您应该可以在 area51 和其他地方使用它

标签: algorithm typescript benchmarking pastebin browser-testing


【解决方案1】:

使用以下流程:

例如,这个 TypeScript 代码:

function add(x: number, y: number): number {
    return x + y;
}

console.log(add(2,2)); // 4

转译后可以进行如下基准测试:

var bench1 = new Benchmark(
  {'fn':add, 'cycles':0,'count':1,'name':'bench1','async':true}
);

function add(x, y) {
    return x + y;
}

function log(result){console.log(JSON.parse(JSON.stringify(result.target.stats)))};

bench1.on('complete', log);
bench1.run();
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.16.6/lodash.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/2.1.2/benchmark.min.js"></script>

参考文献

【讨论】:

    【解决方案2】:

    JavaScript 是 typescript,所以开始用 typescript 编写你的性能测试吧。我能想到的唯一可能会影响性能的打字稿是您在 tsconfig.json 中使用哪个 target - 由于 pollyfills,es5 可能会比 es2018 慢。 js 标准中不存在的语言特性也值得测试,例如https://www.typescriptlang.org/docs/handbook/decorators.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 1970-01-01
      • 2012-06-09
      相关资源
      最近更新 更多