sl133
sl133

Reputation: 1359

Optimize new BufferedReader (Input Stream)

long start = System.currentTimeMillis();
URL link = (any url);
BufferedReader read = new BufferedReader(new InputStreamReader(link.openStream()));
System.out.println("Took: " + (System.currentTimeMillis()-start));

This will print out around 800-1200ms, the webpage itself is not too big, but it is around 300 lines of code.

I am wondering if there is anyway to optimize or speed up the process of opening the stream so that I can readLines of the page source, because while this 1second is not too bad, if you are opening 30 of them up in a program, then you have a problem as it takes 30 seconds. Maybe I should be passing the BufferedReader or InputStreamReader so that it is not making a new one each time?

Thanks

Upvotes: 0

Views: 527

Answers (1)

Jim Garrison
Jim Garrison

Reputation: 86774

99.9% of the time you are seeing is network latency and transmission time. The creation of the reader is microseconds. There's nothing you can do other than get on a faster network and access sites with fat pipes to the Internet.

Upvotes: 2

Related Questions