parse vs round

Benchmark created on


Setup

const floats = [];

for (let i = 0; i < 1000; i++) {
	floats.push(`${i + Math.random()}`);
}

Test runner

Ready to run.

Testing in
TestOps/sec
parse
function parseRating (val) {
  return parseFloat(parseFloat(val).toFixed(2));
}

const result = [];

for (let i = 0; i < floats.lenght; i++) {
	result.push(parseRating(floats[i]));
}
ready
round
function parseRating (val) {
  return Math.round(parseFloat(val)*100)/100;	
}

const result = [];

for (let i = 0; i < floats.lenght; i++) {
	result.push(parseRating(floats[i]));
}
ready

Revisions

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