开发者

Is output buffering more expensive than FS hit?

开发者 https://www.devze.com 2022-12-30 14:42 出处:网络
That\'s abo开发者_JAVA技巧ut it. Is OB heavier than including a file?Output buffering works in RAM.Hitting the filesystem may only hit RAM (cache), but it has the potential to hit the disks.Any time y

That's abo开发者_JAVA技巧ut it. Is OB heavier than including a file?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号