Skip to content

Instantly share code, notes, and snippets.

@bwasti
Created August 15, 2022 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwasti/25951fbda7a61e74ac48613e7295fbbb to your computer and use it in GitHub Desktop.
Save bwasti/25951fbda7a61e74ac48613e7295fbbb to your computer and use it in GitHub Desktop.
import fs from "node:fs"
import readline from "node:readline"
const t0 = performance.now()
const stream = fs.createReadStream("input.txt")
const rl = readline.createInterface({
input: stream,
crlfDelay: Infinity
})
let out = []
for await (const line of rl) {
const [a, b, c] = line.split(',').map(Number)
const n = 4 * a + b * b + (c / 3)
if (out.length && out[out.length - 1] > n) {
out.push(n - out[out.length - 1])
}
out.push(n)
}
const d = (performance.now() - t0) / 1e3
console.log("computed", out.length, "in", d, "seconds")
console.log(out.length / d, "lines/sec")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment