mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
6982c74e11
``` $ dd if=/dev/zero bs=65536 count=500000 | ./stdio # C baseline 500000+0 records in 500000+0 records out 32768000000 bytes transferred in 4.126087 secs (7941664827 bytes/sec) c: size 32768000000 reads 500000 blocksize 65536 ``` ``` $ dd if=/dev/zero bs=65536 count=500000 | deno run stdio.js # Deno 500000+0 records in 500000+0 records out 32768000000 bytes transferred in 4.279032 secs (7657806719 bytes/sec) deno: size 32768000000 reads 500000 blocksize 65536 ```
16 lines
476 B
JavaScript
16 lines
476 B
JavaScript
// From https://github.com/just-js/benchmarks/tree/main/01-stdio
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
|
|
const blocksize = parseInt(Deno.args[0] || 65536);
|
|
const buf = new Uint8Array(blocksize);
|
|
let size = 0;
|
|
let reads = 0;
|
|
|
|
let n = Deno.stdin.readSync(buf);
|
|
while (n > 0) {
|
|
reads++;
|
|
size += n;
|
|
n = Deno.stdin.readSync(buf);
|
|
}
|
|
if (n < 0) throw new Error("Bad Read");
|
|
console.log(`size ${size} reads ${reads} blocksize ${blocksize}`);
|