我有3種打字機算法需要在瀏覽器中進行基準測試。我試過area51,area51只適用於JavaScript。我還發現了一個pastebin:在瀏覽器中使用TypeScript編寫的基準路徑規劃算法
//pastebin.com/gCs9CB5F
有人可以給我一個提示如何在TypeScript上運行基準測試嗎?
我有3種打字機算法需要在瀏覽器中進行基準測試。我試過area51,area51只適用於JavaScript。我還發現了一個pastebin:在瀏覽器中使用TypeScript編寫的基準路徑規劃算法
//pastebin.com/gCs9CB5F
有人可以給我一個提示如何在TypeScript上運行基準測試嗎?
使用以下過程:通過TypeScript playground
例如,這個打字稿代碼
function add(x: number, y: number): number {
return x + y;
}
console.log(add(2,2)); // 4
可以transpilation後進行基準測試如下:
個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>
參考
niutech/typescript-compile: Automatically compile TypeScript to JavaScript on the fly
basarat/typescript-script: Script tag support for TypeScript
Is there a way to get TypeScript to transpile in Plunkr on the client side?
TypeScript: Our Type of JavaScript | Linux.com | The source for Linux information
你能澄清你的問題有點。根本不清楚你在問什麼。 –
根據你使用的環境,你可以將打字稿編譯成普通的javascript,你應該可以在area51和其他地方使用 – Roland