number to string (v49)

Revision 49 of this benchmark created on


Setup

let nums, str;

nums = {
			"n0" : ['NUMBER','PRECISION'], 
			"n1": [1],
			"n2": [1.43435435],
			"n3": [-2.34],
			"n4": [1.0000003],
			"n5": [9384594375.000012340943],
			"n6": [-(0.02**6)],
			"n7": [Number.MIN_VALUE],
			"n8": [5e-26],
			"n9": [0.003440001*0.0000324]
		}
		
const testLoop = (fn) => {
	for(let i = 0; i < nums.length; ++i){
		str = fn(nums[i])
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
String literal
testLoop((num)=>{ 
	return num + "";
})
ready
String constructor
testLoop((num)=>{ 
	return String(num);
})
ready
toString
testLoop((num)=>{ 
	return num.toString();
})
ready
String Literal simple
testLoop((num)=>{ 
	return "" + num;
})
ready
Double String Literal
testLoop((num)=>{ 
	return ''+num+'';
})
ready
Template literals
testLoop((num)=>{ 
	return `${num}`;
})
ready
toLocaleString()
testLoop((num)=>{ 
	return num.toLocaleString();
})
ready
JSON.stringify()
testLoop((num)=>{ 
	return JSON.stringify(num);
})
ready

Revisions

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