JS Perf

Benchmark created on


Setup

function round(value, precision){
 const decimalShift = Math.pow(10, precision);
 const shiftedValue = value * decimalShift;
 return Math.round(shiftedValue) / decimalShift;
}
const num = 545.4345432524532;

Test runner

Ready to run.

Testing in
TestOps/sec
Via String
const roundedNumber = parseFloat(num.toFixed(5));

if(roundedNumber !== 545.43454) {
	throw Error('Inccorect rounding');
}
ready
Math
const roundedNumber = round(num, 5);

if(roundedNumber !== 545.43454) {
	throw Error('Inccorect rounding');
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.