Repository navigation
benchmark: reduce string concatenations - #12455
Closed
vsemozhetbyt wants to merge 4 commits into
Closed
vsemozhetbyt wants to merge 4 commits into
vsemozhetbyt wants to merge 4 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
Affected core subsystem(s)
benchmark
I. Presupposition
String concatenations usually increase syntax noise and add confusion (a reader often has to check if string concatenation or number addition is intended). Moreover, it seems this method is not optimal performance-wise.
II. Cases
This PR aims two cases of string concatenation:
'a' + b + 'c');String('' + notString). This approach, while idiomatic, is not most declarative.III. Performance
The added benchmark compares these variants:
'a' + b + 'c'vs['a', b, 'c'].join('')vs`a${b}c`String(notString)vs'' + notStringvs`${notString}`Results with Node.js 8.0.0 rc:
IV. Commits
Reduce string concatenations: replace concatenations with template literals, rewrap,
String.prototype.repeat(),String(). Some replacements do not add indisputable readability gain, but I tried to be consistent.Add a benchmark for string concatenations vs counterparts.
This commit is added here to avoid PR race condition and merge conflicts. It fixes an URL in
_http-benchmarkers.js(removes duplicate hash symbol).This commit is added here to avoid PR race condition and merge conflicts. It fixes an evident typo in
_http-benchmarkers.js:Error()constructor has only one parameter, whilecallback()has 5 (compare a previous call andcallback()signature).All changed files were minimally tested. CI for linting and new tests concerning benchmarks will be launched.