Ziya ERKOC
Ziya ERKOC

Reputation: 839

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?

Upvotes: 2

Views: 1273

Answers (1)

Kylon Tyner
Kylon Tyner

Reputation: 391

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)

Upvotes: 7

Related Questions