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

Unpacked size is greater than esprima & espree. Speed is similar #240

Open
80avin opened this issue Dec 26, 2022 · 1 comment
Open

Unpacked size is greater than esprima & espree. Speed is similar #240

80avin opened this issue Dec 26, 2022 · 1 comment

Comments

@80avin
Copy link

80avin commented Dec 26, 2022

I was comparing it with other alternatives like esprima and espree.
From what I found, esprima & espree have lot of features but have smaller Unpacked size as reported by npm.

It is relatively faster, but considering the small scope of it's features, I don't think that performance gain is beneficial. (Like if we have to run small expressions, then every library does it within 20ms and 10-20ms is not big gain).

For reference,

criteria jsep esprima espree
Unpacked size 388kB 314kB 76.4kB
Features minimal complete JS complete JS
benchmark time 274 491 417

benchmark code

import jsep from 'jsep';
import * as espree from 'espree';
import * as esprima from 'esprima';
import {Bench} from 'tinybench';

const script = '2+'.repeat(1000) + '1';

const bench = new Bench({time: 100});
bench
  .add('jsep', () => {jsep(script)})
  .add('esprima', () => {esprima.parseScript(script)})
  .add('espree', () => {espree.parse(script)})
    ;

bench.run().then(t => console.table(t.map(tt => ({name: tt.name, avg: tt.result.mean*1000, var: tt.result.variance*1000})))).catch(e => console.error(e))
/* Console
┌─────────┬───────────┬────────────────────┬────────────────────┐
│ (index) │   name    │        avg         │        var         │
├─────────┼───────────┼────────────────────┼────────────────────┤
│    0    │  'jsep'   │ 274.0221922120003  │  49.0996204188163  │
│    1    │ 'esprima' │ 491.28853894916233 │ 286.50706192948815 │
│    2    │ 'espree'  │ 417.70407563696307 │ 304.5463155112307  │
└─────────┴───────────┴────────────────────┴────────────────────┘
*/

After this, I became curious to know what is the selling point of jsep and why/when should one prefer it over others ?

@Strate
Copy link

Strate commented Dec 27, 2022

I think that npm reports unpacked size of all files in package (not only executable code). jsep ships with 3 different bundles (commonjs, iife, module) and sourcemaps for this

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