---------- Forwarded message ---------- From: Maksim Lin <[email protected]> Date: Wed, 8 Apr 2009 08:30:44 +1000 Subject: Re: HTTP Request To: Joran <[email protected]>
I think your problem might be the large number of string concat ops you are doing. It might be worth trying to use a Java StringBuffer object instead. Maks. On 4/7/09, Joran <[email protected]> wrote: > I've written some simple js functions to do HTTP Get, Post, Put and > Delete requests using java.net.URL. > > However, whereas Curl or the browser can make the same request in > under 1 second, my implementation in Rhino/Java takes 4 seconds on > average. I've traced the bulk of this time to the following code I use > to read the response: > > try { > var stream = new java.io.InputStreamReader > (this.connection.getInputStream(), 'UTF-8'); > } catch (e) { > var stream = new java.io.InputStreamReader > (this.connection.getErrorStream(), 'UTF-8'); > } > var input = new java.io.BufferedReader(stream); > if (input) { > var line = ''; > while ((line = input.readLine()) !== null) { > this.response.representation += line; > } > this.response.representation += ''; // Convert to Javascript string. > input.close(); > } > > The response being processed with this is about 244kb and as mentioned > it's about 3 seconds slower than Curl or browser. > > Would anyone have any suggestions? Help would be much appreciated. > Thanks. > _______________________________________________ > dev-tech-js-engine-rhino mailing list > [email protected] > https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino > _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
