Git Product home page Git Product logo

json-parse-benchmark's Introduction

Benchmarking JSON vs JSON5

Recent stirrings in the JavaScript Twitter community have brought a lot of attention to the shortcomings of JSON as a human-readable format, and proposed allowing JSON5 in place of it. JSON5 is a superset of JSON that allows for comments, trailing commas, and more. This is a great idea for more human-readable JSON, but I was curious about the performance implications of defaulting to JSON5 over JSON, since parsing JSON, being CPU-bound, can already be a bottleneck in many web services.

The benchmark includes 3 tests for each JSON and JSON5. All are valid JSON, which makes up the majority of JSON usage in the wild. All the test payloads have the same structure, but vary in the quantity of data they contain. The tests are as follows:

  • Test 1: Small input: 4.36KiB
  • Test 2: Medium input: 27.59KiB
  • Test 3: Large input: 1407.77KiB

Disclaimer

This benchmark is not meant to be a comprehensive comparison of JSON and JSON5. It is a simple benchmark that compares the performance of JSON and JSON5 in an environment where parsing JSON payloads is a common task. This does not represent any meaningful performance difference for 1-time payloads, like reading a configuration file, which JSON5 may be more targeted to.

Results

The benchmark was run on Ubuntu 20.04, Node.js v20.12.2, on an older Intel [email protected] with 32GB of GDDR5 RAM.

Small input: 4.36KiB

(index) name ops/sec average (ms) samples relative to JSON small
0 'JSON small' 85056 '0.012' 850566 ''
1 'JSON5 small' 2006 '0.498' 20063 '42.40 x slower'

Medium input: 27.59KiB

(index) name ops/sec average (ms) samples relative to JSON medium
0 'JSON medium' 12938 '0.077' 129383 ''
1 'JSON5 medium' 315 '3.172' 3153 '41.07 x slower'

Large input: 1407.77KiB

(index) name ops/sec average (ms) samples relative to JSON large
0 'JSON large' 243 '4.099' 2440 ''
1 'JSON5 large' 5 '174.584' 58 '48.60 x slower'

Running the benchmark

npm install
npm start

json-parse-benchmark's People

Contributors

shamsup avatar

Stargazers

Toni Villena avatar

Watchers

 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.