我注意到在deno中读取文件的速度非常缓慢,恐怕我做错了。(有点傻?)
const file = Deno.readFileSync(path)有什么建议吗?或者其他更快的方法?我应该用Deno.run代替吗?在您的经验中,Deno.run的利弊是什么?
更新#1:
我发现这个模块使用的流提供了一些更快的速度,但是与bash相比,它非常慢:
$ time deno run --allow-read https://deno.land/std@0.126.0/examples/cat.ts movie.mp4 | wc -l
4066379
real 0m1.890s
user 0m1.608s
sys 0m1.355s
$ time cat movie.mp4 | wc -l
4066379
real 0m0.295s
user 0m0.098s
sys 0m0.372s
$ du -sh movie.mp4
995M movie.mp4更新#2:
由于对网络速度和Deno启动速度的担忧,我制作了这个脚本,它让它们分别运行:
import {
copy,
writeAllSync,
} from "https://deno.land/std@0.126.0/streams/conversion.ts";
const filenames = "movie.mp4";
//########## DENO ############
const before1 = performance.now();
const file = await Deno.open(filenames);
await copy(file, Deno.stdout);
file.close();
const after1 = performance.now() - before1;
const text1 = new TextEncoder().encode(after1.toString() + "\n");
writeAllSync(Deno.stderr, text1);
//########## CMD ############
const before2 = performance.now();
const p = Deno.run({
cmd: ["cat", `${filenames}`],
});
await p.status()
const after2 = performance.now() - before2;
const text2 = new TextEncoder().encode(after2.toString() + "\n");
writeAllSync(Deno.stderr, text2);最好的结果是:
$ deno run --allow-run --allow-read test.ts >/dev/null
636
82https://stackoverflow.com/questions/71175337
复制相似问题