benchmark: output JSON-compatible numbers

This is to simplify the implementation of a JavaScript version of the
compare.R script.

PR-URL: https://github.com/nodejs/node/pull/38778
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
This commit is contained in:
Michaël Zasso 2021-05-23 11:28:18 +02:00 committed by James M Snell
parent a43a140ef5
commit 2a1dea8a22
No known key found for this signature in database
GPG Key ID: 7341B15C070877AC

View File

@ -267,7 +267,7 @@ class Benchmark {
function nanoSecondsToString(bigint) {
const str = bigint.toString();
const decimalPointIndex = str.length - 9;
if (decimalPointIndex < 0) {
if (decimalPointIndex <= 0) {
return `0.${'0'.repeat(-decimalPointIndex)}${str}`;
}
return `${str.slice(0, decimalPointIndex)}.${str.slice(decimalPointIndex)}`;