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

Improve performance #11

Merged
merged 1 commit into from
Nov 12, 2023
Merged

Improve performance #11

merged 1 commit into from
Nov 12, 2023

Conversation

sindresorhus
Copy link
Owner

Fixes #10

Apparently, creating a vm context is very expensive. It now reuses the context. This should in theory be safe as JavaScript is single-threaded, so two functions cannot execute, for example, firstMatch at the same time. But it does make me think whether there's anything I'm missing.

// @fityannugroho


❯ nr benchmark

> [email protected] benchmark
> node benchmark/index.js

str.matchAll: 0.236ms
matches: 2.355ms
matches-t500: 16.928ms
str.match: 0.149ms
firstMatch: 2.334ms
firstMatch-t500: 22.152ms

	Count chars: 23749
	Count rows: 405
	Count matches: 363 363 363 363 363 363

Copy link

@fityannugroho fityannugroho left a comment

Choose a reason for hiding this comment

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

I have tested it on my own device, and I think it is already fast enough.

str.matchAll: 0.663ms
matches: 10.594ms
matches-t500: 84.115ms
str.match: 0.469ms
firstMatch: 10.175ms
firstMatch-t500: 106.647ms

        Count chars: 23749
        Count rows: 405
        Count matches: 363 363 363 363 363 363

@sindresorhus sindresorhus merged commit c45483a into main Nov 12, 2023
4 checks passed
@sindresorhus sindresorhus deleted the perf branch November 12, 2023 10:11
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.

firstMatch and matches are too slow for large string
2 participants