Skip to content

perf: typeof will be faster (vs instanceof)#242

Closed
nigrosimone wants to merge 1 commit into
dimdenGD:mainfrom
nigrosimone:type-of
Closed

perf: typeof will be faster (vs instanceof)#242
nigrosimone wants to merge 1 commit into
dimdenGD:mainfrom
nigrosimone:type-of

Conversation

@nigrosimone

Copy link
Copy Markdown
Contributor

typeof will return one of the built in types (Object, undefined and the primitives). The instanceof operator should check the prototype chain and see if the right side has been used as a constructor somewhere along. This is naturally more work.

@nigrosimone nigrosimone changed the title perf: typeof will be faster perf: typeof will be faster (vs instanceof) Aug 17, 2025
@dimdenGD

Copy link
Copy Markdown
Owner

I check if its Regexp, not if its object

@dimdenGD dimdenGD closed this Aug 17, 2025
@nigrosimone

Copy link
Copy Markdown
Contributor Author

Pattern only can be "string" or "RegExp" (object)

typeof seem faster https://jsperf.app/typeof-function-vs-instanceof/5

@dimdenGD

Copy link
Copy Markdown
Owner

There's no point in making this function faster, it only gets called once during server init. And even if it was called on every request, this is still pretty much a pointless microoptimization that probably brings like +1 req/sec benefit... No point

@nigrosimone
nigrosimone deleted the type-of branch April 4, 2026 04:04
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.

2 participants