Skip to content

Instantly share code, notes, and snippets.

@youurayy
Created June 28, 2020 16:27
Show Gist options
  • Save youurayy/18553475c5a9f81a17345cddeebc5d08 to your computer and use it in GitHub Desktop.
Save youurayy/18553475c5a9f81a17345cddeebc5d08 to your computer and use it in GitHub Desktop.
will read un-gzipped test data from https://github.com/pkg/json/tree/master/testdata; run as: deno run -A test-deno.js
import { readJsonSync }
from "https://deno.land/std/fs/mod.ts";
const repetitions = 100
const dir = './testdata'
for(const file of Deno.readDirSync(dir)) {
const fileName = `${dir}/${file.name}`
const bytes = Deno.statSync(fileName).size
let i = 1, avg = 0
for(; i <= repetitions; i++) {
const t = Date.now()
const parsed = readJsonSync(fileName)
const duration = Date.now() - t
avg += duration
}
avg /= i
const mbs = '' + Math.round((bytes / 1e6) / (avg / 1000))
const avgMs = '' + Math.round(avg)
console.log(` ${file.name.padEnd(20, ' ')} --> ` +
`${avgMs.padStart(4, ' ')} ms, ` +
`${mbs.padStart(4, ' ')} MB/s`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment