问题是,当尝试在任何类型的循环中运行 BUFFER.writeSync 时,由于某种原因它不会向缓冲区写入任何内容,在 for 循环之外它会正常写入。
控制台中的预期列表文本一无所获。 代码:
import { BufWriterSync } from "https://deno.land/[email protected]/io/buf_writer.ts";
const BUFFER = BufWriterSync.create(Deno.stdout);
const TEXT_ENCODER = new TextEncoder();
function main() {
const range = new Uint32Array().fill(1, 0, 1000);
//BUFFER.reset(Deno.stdout);
range.forEach(number => {
BUFFER.writeSync(TEXT_ENCODER.encode(number.toString()))
if (!isEven(number)) {
BUFFER.writeSync(TEXT_ENCODER.encode(`${number} is odd`));
} else {
BUFFER.writeSync(TEXT_ENCODER.encode(`${number} is even`));
}
})
console.log(BUFFER.buffered());
}
Deno.bench("benchmark", function () {
main();
});
function isEven(num: number): boolean {
return num % 2 == 0;
}
if (import.meta.main) {
main();
}
您没有看到预期的控制台写入,因为您的
range
数组是空的。
例如尝试将
length
值(例如 2000
)传递给您的 new Uint32Array()
构造函数调用:
const range = new Uint32Array(2000).fill(1, 0, 1000);
示例输出:
11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd11 is odd00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 is even00 i2616