I have 3 typescript algorithms I need to benchmark in the browser. I tried area51, area51 is only for JavaScript. I also found a pastebin:
//pastebin.com/gCs9CB5F
Can someone give me a hint how to run a benchmark on TypeScript?
I have 3 typescript algorithms I need to benchmark in the browser. I tried area51, area51 is only for JavaScript. I also found a pastebin:
//pastebin.com/gCs9CB5F
Can someone give me a hint how to run a benchmark on TypeScript?
Use the following process:
For example, this TypeScript code:
function add(x: number, y: number): number {
return x + y;
}
console.log(add(2,2)); // 4
Can be benchmarked after transpilation as follows:
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>
References
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 is typescript, so start writing your performance test in typescript. The only ting typescript could affect performance that I can think of is which target do you use in tsconfig.json - probably es5 will be slower than es2018 because of pollyfills. Also language features that don't exists in js standard would be interesting to test, for example https://www.typescriptlang.org/docs/handbook/decorators.html