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

Performance for escaping strings #16

Open
joliss opened this issue Jan 2, 2014 · 3 comments
Open

Performance for escaping strings #16

joliss opened this issue Jan 2, 2014 · 3 comments

Comments

@joliss
Copy link

joliss commented Jan 2, 2014

For escaping strings, jsesc is about 10x slower than js-string-escape:

$ time node -e "var escape=require('jsesc'); for (var i = 0; i < 1000000; i++) { escape('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') }"

real    0m2.490s
user    0m2.485s
sys 0m0.024s
$ time node -e "var escape=require('js-string-escape'); for (var i = 0; i < 1000000; i++) { escape('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') }"

real    0m0.217s
user    0m0.170s
sys 0m0.051s

This turns out to be relevant in practice: Building my sample JavaScript app takes twice as long when I use jsesc.

joliss added a commit to joliss/broccoli-es6-concatenator that referenced this issue Jan 2, 2014
jsesc turns out to be about 10x slower than js-string-escape. See
mathiasbynens/jsesc#16

This reverts commit 0a9f14c.
@mathiasbynens
Copy link
Owner

Any ideas on how to improve jsesc’s performance?

I guess this is the cost we pay for the additional functionality compared to js-string-escape, no?

@joliss
Copy link
Author

joliss commented Mar 19, 2014

I'd be surprised if there's anything fundamentally stopping us from optimizing jsesc. If I wanted to optimize jsesc, I'd probably try different approaches to the inner escape loop.

@joliss
Copy link
Author

joliss commented Mar 19, 2014

I remember trying a bunch of implementations for js-string-escape, and replace surprisingly turned out to be quite fast, despite the closure function.

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

No branches or pull requests

2 participants