-1

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?

2
  • Can you clarify your question a bit. It's not clear at all what you are asking. Commented Jul 7, 2017 at 5:07
  • Depending on the environment your using you can compile the typescript into plain javascript which you should be able to use in area51 and other places Commented Jul 7, 2017 at 5:14

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.