On Wed, 21 Sep 2005 05:29 pm, Jeremias Maerki wrote: > On 21.09.2005 11:21:50 ALi wrote: > > this is my code ... > > xml is in resultstr (<?xml ...........>) > > xslt is the name of the file (/name.file.xsl) > > long tiempo1 = System.currentTimeMillis(); > > long tiempo2 = 0; > > // Construct fop with desired output format > > Driver driver = new Driver(); > > driver.setRenderer(Driver.RENDER_PDF); > > // Setup output > > try { > > java.io.ByteArrayOutputStream out = new > > java.io.ByteArrayOutputStream(); //out = new > > java.io.BufferedOutputStream(out); > > try { > > driver.setOutputStream(out); > > // Setup XSLT > > TransformerFactory factory = TransformerFactory.newInstance(); > > Transformer transformer = factory > > .newTransformer(new StreamSource(xsltfile)); > > That's exactly it. You reload the stylesheet every time. If you > create a stylesheet cache, you can simply reuse Templates instances. > Why would cacheing the stylesheet make the first invocation faster? The original question was about executing a transformation multiple times in a loop and why the first invocation takes so much longer than the second and by the 3rd execution times becomes stable. I still think these time differences are solely JVM/application startup/warmup related and have nothing to do with cacheing the stylesheet as that would only make subsequent invocations faster.
Manuel > //Create the Templates object and store it in the cache > Templates templates = factory.newTemplates(new > StreamSource(xsltfile)); > > //To create the Transformer with the Templates objects from the cache > Transformer transformer = templates.newTransformer(); > > > // Set the value of a <param> in the stylesheet > > transformer.setParameter("versionParam", "2.0"); > > // Setup input for XSLT transformation > > Source src = new StreamSource(new StringReader(resultStr)); > > // Resulting SAX events (the generated FO) must be piped through to > > FOP Result res = new SAXResult(driver.getContentHandler()); > > // Start XSLT transformation and FOP processing > > transformer.transform(src, res); > > tiempo2 = System.currentTimeMillis(); > > response.setContentType("application/pdf"); > > byte[] cont = out.toByteArray(); > > response.setContentLength(cont.length); > > response.getOutputStream().write(cont); > > response.getOutputStream().flush(); > > } catch (TransformerException e) { > > logger.warn("Error generando pdf :" + e.getMessage()); > > } finally { > > out.close(); > > } > > } catch (FileNotFoundException e) { > > e.printStackTrace(); > > } catch (IOException e) { > > logger.debug("Error cerrando el fichero " + e.getMessage()); > > } > > logger.info("Tiempo 1:" + tiempo1); > > logger.info("Tiempo 2:" + tiempo2); > > logger.info("Total :" + (tiempo2 - tiempo1)); > > > > On 9/21/05, Jeremias Maerki <[EMAIL PROTECTED]> wrote: > > > I assume the operating system has very little influence on the > > > time here. The fact that ALi has a big difference in the first > > > couple of invocations is a clear indicator that he experiences > > > the effect of class loading and just-in-time compiling by the > > > JavaVM. And yes, ALi, the stylesheets have to be "compiled" (or > > > at least parsed) but I guess from your code that this happens > > > each time in your case. Unfortunately, we don't see the code of > > > your makePDF() method. > > > > > > You can reuse the "pre-compiled" XSLT stylesheet if you use the > > > JAXP Templates object. Please note that it's not FOP that > > > compiles the XSLT stylesheet. It's probably you in makePDF() by > > > using JAXP. FOP only processes the output of the XSL > > > transformation. There are lots of articles on the web (like the > > > following) that demonstrate how to cache Templates instances: > > > http://www.javaworld.com/javaworld/jw-05-2003/jw-0502-xsl.html > > > > > > On 21.09.2005 10:22:22 Manuel Mall wrote: > > > > Are you sure its not your operating system which causes the > > > > time differences. Even OSes tend to warm up, ie. the first time > > > > around existing stuff gets swapped out and the new code loaded. > > > > Next time around this is not required any more. > > > > > > > > Manuel > > > > > > > > On Wed, 21 Sep 2005 04:07 pm, ALi wrote: > > > > > Hello i have problems with times in generating pdf > > > > > I want to know why the times are so different between one > > > > > invocation and two > > > > > > > > > > > > > > > for example i have the class makePDF > > > > > > > > > > main () { > > > > > time1 > > > > > makePDF(xml,xsl); > > > > > time2 > > > > > println(time2-time1) > > > > > } > > > > > the times are over 8 seconds > > > > > more or less (with my xsl) > > > > > > > > > > if i have > > > > > main () { > > > > > for (1-10) { > > > > > time1 > > > > > makePDF(xml,xsl); > > > > > time2 > > > > > println(time2-time1) > > > > > } > > > > > } > > > > > > > > > > the first time is 8 seconds, but the seconds ones are less > > > > > but much less the second is 3 seconds the third 1500 > > > > > miliseconds and after over 300 miliseconds ..... > > > > > why is these? is it because the fop need to compile the xsl? > > > > > Are any form to force to cache the compilation of xsl? (in > > > > > order to always take the same time. > > > > > > > > > > We have different xsl and one class that makes alls > > > > > > > > > > > > > > > thx for your help > > > > > > Jeremias Maerki > > > > > > many thx for the url jeremias > > Jeremias Maerki > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]