-
Notifications
You must be signed in to change notification settings - Fork 28.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
benchmark: improve compare output #18597
Conversation
The current output uses JSON.stringify to escape the config values. This switches to util.inspect to have a better readable output.
benchmark/compare.js
Outdated
} | ||
conf = conf.slice(1); | ||
// Escape quotes (") for correct csv formatting | ||
conf = conf.replace(/"/g, '""'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does using inspect
prevent quotes completely from appearing? Could data.conf[key]
not contain a "
itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconding this question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, you are right. I was a bit hasty here. I revert that change.
@@ -76,11 +77,9 @@ if (showProgress) { | |||
// Construct configuration string, " A=a, B=b, ..." | |||
let conf = ''; | |||
for (const key of Object.keys(data.conf)) { | |||
conf += ` ${key}=${JSON.stringify(data.conf[key])}`; | |||
conf += ` ${key}=${inspect(data.conf[key])}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually wondering, is there a place where we benefit from using inspect
here as opposed to simply String(data.conf[key])
? Because as far as I can tell, conf
is generally number, string or true/false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do because we will actually be able to distinguish the data types by using util.inspect
. By only converting it to a string, the string 'true'
would look the same as the boolean true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair.
Personally, I'm not sure I actually love that part of the functionality but obviously that's not something that needs to be addressed in this PR. Since it's generating CSV, having true and "true" be equivalent is almost preferable to me.
One other thing... util.inspect
will do the following:
util.inspect("true");
// '\'true\''
JSON.stringify("true");
// '"true"'
The former doesn't seem correct for the purposes of CSV.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW one of the problems with single quotes is there seems to be no accepted way of handling them. Some parsers seem to treat them as equivalent to double quotes (meaning they need to be escaped) and others treat them as just a character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apapirovski I wrote this with the RFC 4180 specs in mind. If a parser does something else (and many do), then that is just tough luck. Creating CSV files that work in all parsers is a very big challenge. We just need to make sure it works with read.csv
in R
.
benchmark/compare.js
Outdated
} | ||
conf = conf.slice(1); | ||
// Escape quotes (") for correct csv formatting | ||
conf = conf.replace(/"/g, '""'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconding this question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring CSV silliness, this seems good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, you should run the benchmark CI job on something fast, just to make sure it works.
Landed in 809af1f |
The current output uses JSON.stringify to escape the config values. This switches to util.inspect to have a better readable output. PR-URL: #18597 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The current output uses JSON.stringify to escape the config values. This switches to util.inspect to have a better readable output. PR-URL: #18597 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The current output uses JSON.stringify to escape the config values. This switches to util.inspect to have a better readable output. PR-URL: #18597 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The current output uses JSON.stringify to escape the config values. This switches to util.inspect to have a better readable output. PR-URL: #18597 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The current output uses JSON.stringify to escape the config values. This switches to util.inspect to have a better readable output. PR-URL: #18597 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The current output uses JSON.stringify to escape the config values. This switches to util.inspect to have a better readable output. PR-URL: #18597 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The current output uses JSON.stringify to escape the config values. This switches to util.inspect to have a better readable output. PR-URL: nodejs#18597 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The current output uses JSON.stringify to escape the config values.
This switches to util.inspect to have a better readable output.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
benchmark