Code Monkey home page Code Monkey logo

superjson-and-devalue's Introduction

superjson-and-devalue

quick script to compare the performance/output of superjson and devalue, following this Twitter thread.

git clone [email protected]:Rich-Harris/superjson-and-devalue
cd superjson-and-devalue
npm i
node index.js

The sample object is small and simple โ€” different objects may have different outcomes.

Note: I couldn't get things like Sets or repeated references to work with superjson (it complained about circular references).

superjson and devalue results

Bundle size

To see how much superjson.deserialize adds to the client bundle, run this:

npm run build
cat bundle-size/output-superjson.js | wc -c

(With Terser installed globally, you can do cat bundle-size/output-superjson.js | terser -cm | wc -c to check minified size, or chuck a | gzip -9 in there to see zipped size.)

Results

In node 16.15.1 on an M1 Max, [email protected] handily beats [email protected] on all tests:

superjson output: 183 bytes
devalue output: 116 bytes

() => superjson.stringify(obj)
1000000 iterations in 8543ms

() => devalue(obj)
1000000 iterations in 3190ms

() => superjson.parse(superjson_serialized)
1000000 iterations in 3343ms

() => eval(`(${devalue_serialized})`)
1000000 iterations in 261ms

superjson.deserialize adds 12.3kb to your client bundle size. (devalue adds 0kb, because there's no runtime.)

superjson-and-devalue's People

Contributors

rich-harris avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.