Skip to content
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

chore: change lastindexOf to endsWith #3799

Merged
merged 1 commit into from Mar 29, 2022
Merged

Conversation

xtx1130
Copy link
Contributor

@xtx1130 xtx1130 commented Mar 29, 2022

Optimized from last pr: #3789

Checklist

@xtx1130
Copy link
Contributor Author

xtx1130 commented Mar 29, 2022

benchmark for fastify:

this branch:
image
master:
image


benchmark for code:

const { version } = require('process')
const max = 100000000


function useEndsWith () {
  let value = '1234567890;'
  if(value.endsWith(';'))
    return true
}
function useLastIndexOf () {
  let value = '1234567890;'
  if(value.lastIndexOf(';') === value.length-1)
    return true
}

console.log(version)

console.time('useEndsWith')
for (let i = 0; i < max; i++) {
  useEndsWith()
}
console.timeEnd('useEndsWith')

console.time('useLastIndexOf')
for (let i = 0; i < max; i++) {
  useLastIndexOf()
}
console.timeEnd('useLastIndexOf')

output:

$ v14.19.0
$ useEndsWith: 1.232s
$ useLastIndexOf: 2.477s

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

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

LGTM.

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! Amazing

@mcollina mcollina merged commit b9046c2 into fastify:main Mar 29, 2022
@xtx1130 xtx1130 deleted the use-endsWith branch March 29, 2022 08:44
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants