-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
perf: remove regexp-clone #11327
perf: remove regexp-clone #11327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad that we're getting rid of more and more dependencies.
Have a couple of questions and suggestions regarding the introduced changes, but I'm happy with that change.
@AbdelrahmanHafez |
@AbdelrahmanHafez regexp-clone x 2,177,401 ops/sec ±1.10% (87 runs sampled) So intuitivly, we have implemented the fastest cloning const Benchmark = require('benchmark');
const cloneRegExp = require('regexp-clone');
const regex = /^a$/g;
new Benchmark.Suite()
.add('regexp-clone', function () {
const newRegex = cloneRegExp(regex)
})
.add('new RegExp(regex)', function () {
const newRegex = new RegExp(regex);
if (typeof regex.lastIndex === "number") {
newRegex.lastIndex = regex.lastIndex;
}
})
.add('new RegExp(regex.source, regex.flags)', function () {
const newRegex = new RegExp(regex.source, regex.flags);
if (typeof regex.lastIndex === "number") {
newRegex.lastIndex = regex.lastIndex;
}
})
.on('cycle', function (evt) {
console.log(String(evt.target));
})
.run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks 👍 I also agree about removing deps.
Cloning an regexp does not need an external library.