benjamin parker wrote:I have a code below that is reading large image size and writing them to file however the process is too slow.
Joanne
benjamin parker wrote:i don't think it is due to writing to file that is taking a long time. probably the downloading part?
Joanne
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
--- Martin Fowler
fred rosenberger wrote:"too slow" is also not a good spec. How fast should it be? What is acceptable and what is not? You would usually define some kind of through-put. I.e. saying "a file should download in one second" is no good, since file A might be 10k, but file B could be 2GB.
Dave Tolls wrote:Though this is quite true, I will say that transferring from InStream to OutStream a byte at a time is a fairly basic error in this sort of thing.
I wouldn't consider changing this code from the current byte-in, byte-out mode to a byte[] mode to be premature optimisation.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Dave Tolls wrote:Though this is quite true, I will say that transferring from InStream to OutStream a byte at a time is a fairly basic error in this sort of thing.
I wouldn't consider changing this code from the current byte-in, byte-out mode to a byte[] mode to be premature optimisation.
I would. Calling a Java method a million times might be a drop in the ocean compared to something like disk latency, since method calls take nanoseconds, and if raw transfer is what is required, then byte-for-byte calls may be the only way to go.
What I would agree with is that a code review may well be the right forum for working out where the bottleneck is occurring; but don't just assume that it's the "byte-for-byte" side of things just because it generates a lot of method calls.
Winston
Dave Tolls wrote:It's not because it generates a lot of method calls.
It's because a generates a lot of traffic.
It's a FOS, so disk write is invariably a problem.
I don't think I've seen an instance where writing to a file byte for byte is not a mistake. Which is why I've mentioned it.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
It's a tiny ad only because the water is so cold.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
|