Skip to content

Conversation

@nigrosimone
Copy link
Contributor

Comparing more values in a single if statement has a little performance hit instead of make multiple if statement. In general, combining multiple comparisons into one if statement might result in slightly better performance due to reduced overhead from evaluating conditions and executing multiple control flow structures. This is because combining conditions can reduce the number of times the JavaScript engine has to evaluate expressions and jump between different parts of the code.

benchmark (master VS PR)

short string............................................. x 16,634,103 ops/sec ±2.06% (182 runs sampled)

short string............................................. x 18,920,179 ops/sec ±1.07% (184 runs sampled)

PR seems better!

Checklist

Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 64e163d into fastify:master Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants