简体   繁体   中英

Why reading and array of bytes at a time is faster than reading one byte?

"Reading an array of bytes at a time is much faster than reading one byte at a time"
I saw the sentence there while i was trying to learn for input stream. Why this is the case?

It's not that obtaining an array of 50 bytes is faster than obtaining 1 byte. It's that over time, it is faster to get 1,000,000,000 bytes of data in chunks of 50 than it is to get 1,000,000,000 bytes one by one.

It's the same reason we don't go to the grocery store for one thing at a time.
It's the trip that takes the most time, not the amount of groceries that we get.
(groceries being bytes in this example, and trip being the retrieval of data from memory)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM