输出缓冲比 FS 命中更昂贵吗?

发布于 2024-09-02 06:50:20 字数 24 浏览 3 评论 0原文

就是这样。 OB 比包含文件重吗?

That's about it. Is OB heavier than including a file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请恋爱 2024-09-09 06:50:20

输出缓冲在 RAM 中工作。访问文件系统可能只会访问RAM(缓存),但也有可能访问磁盘。每次访问磁盘时,与直接 RAM 访问相比,您都会发现速度至少慢了一个数量级。

Output buffering works in RAM. Hitting the filesystem may only hit RAM (cache), but it has the potential to hit the disks. Any time you hit the disks, you're looking at at least an order of magnitude of slowness compared to straight RAM access.

自在安然 2024-09-09 06:50:20

我想说取决于您的系统的昂贵程度...如果您绝对必须使用尽可能少的内存,那么直接写入磁盘可能是您唯一的选择,尽管底层系统的“磁盘写入”实现仍然会尽可能分块写出,因为您可能不会为每个字符调用“write”。

最后,合理的缓冲速度更快......最简单的测试方法是写出一大串字符,一次一个字符,然后将字符串分成几个合理的块。

考虑到这一点,我想不出为什么你不至少在某种程度上缓冲你的输出!如果您所做的只是将文件从一个地方复制到另一个地方,那么使用系统调用(如果可用)可能比在 PHP 中读取、缓冲和写入快得多。

I'd say depends on what's expensive on your system... if you absolutely must use the smallest amount of memory possible, then writing directly to disk may be your only option, although the underlying system's implementation of a 'disk write' will still write out in chunks when it can, since you're probably not calling 'write' for each character.

In the end, buffering within reason is faster... the easiest way to test is by writing out a large string of characters, one character at a time, then the string in a few reasonable chunks.

With that in mind, I can't think of why you wouldn't buffer your output at least somewhat! If all you're doing is copying a file from one place to another, using a system call (if available) is probably much faster than it would be reading, buffering and writing in PHP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文