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

benchmark: add util.toUSVString()'s benchmark #40203

Closed
wants to merge 1 commit into from

Conversation

XadillaX
Copy link
Contributor

I've tried to replace toUSVString()'s code with:

const surrogateRegexp = new RegExp('((?<![\ud800-\udbff])[\udc00-\udfff]|[\ud800-\udbff](?![\udc00-\udfff]))', 'g');
function toUSVString(val) {
  const str = `${val}`;
  if (!str) return str;
  return str ? str.replace(surrogateRegexp, '\ufffd') : str;
}

And run with the new benchmark:

# Pure JavaScript version
util/to-usv-string.js
util/to-usv-string.js size=10 n=100000: 1,289,465.0614219273
util/to-usv-string.js size=100 n=100000: 153,611.6972579318
util/to-usv-string.js size=500 n=100000: 31,669.01363984956

# Original version of Node.js
util/to-usv-string.js
util/to-usv-string.js size=10 n=100000: 3,030,237.0078664045
util/to-usv-string.js size=100 n=100000: 504,156.9606788727
util/to-usv-string.js size=500 n=100000: 108,351.93040720205

The original version is faster. So I decided to only add the benchmark and do not modify the implement.

@nodejs-github-bot nodejs-github-bot added benchmark Issues and PRs related to the benchmark subsystem. util Issues and PRs related to the built-in util module. labels Sep 24, 2021
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

@XadillaX
Copy link
Contributor Author

Landed in 0ee0ed1

@XadillaX XadillaX closed this Sep 27, 2021
XadillaX added a commit that referenced this pull request Sep 27, 2021
PR-URL: #40203
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
targos pushed a commit that referenced this pull request Oct 4, 2021
PR-URL: #40203
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmark Issues and PRs related to the benchmark subsystem. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants