我正在评估JasperReports和Birt报告引擎。
我在两个工具中设计了一个简单的报告,其中我给报告提供了20个值作为参数,并从报告中的SQL选择中填充了另外6个值作为详细关系(这意味着我有许多行)。
我使用Java编程创建了两个报告和PDF导出(我认为两个报告引擎都使用iText)
我测量了每个报告所需的时间。这两个报告完全相同,并且从同一进程运行。
该报告已针对10组值运行。因此,我测量了10份报告的时间。结果如下:
打印Jasper报告 10个值。测量所需时间。 110 109 141 125 110 125 110 125 109 110 Jasper完成!!!
打印Birt报告 10个值。测量所需时间。 1063 1017 1095 1079 1063 1079 1048 1064 1079 1080 Birt完成!!!
数字以msecs为单位。
Jasper比Birt快10倍是否可能?我的代码是否存在问题,导致Birt变慢? 我会发布我在每种情况下使用的代码:
JasperReports:
// Export Jasper report
long startTime = System.currentTimeMillis();
JasperPrint myJasperPrint;
JRExporter myJRExporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
try {
myJRExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C:/Workspace/myProject/jasperReport" + reportNr + ".pdf");
myJasperPrint = JasperFillManager.fillReport("C:/Workspace/myProject/reports/testReport.jasper", jasperParametersMap, connection);
myJRExporter.setParameter(JRExporterParameter.JASPER_PRINT, myJasperPrint);
myJRExporter.exportReport();
return (System.currentTimeMillis() - startTime);
} catch (JRException ex) {
System.out.println(ex);
}
Birt:
// Export Birt report
String format = HTMLRenderOption.OUTPUT_FORMAT_PDF;
EngineConfig config = new EngineConfig();
config.setEngineHome("C:\\Tools\\Eclipse\\plugins\\org.eclipse.birt.report.viewer_4.2.2.v201302041142\\birt");
HTMLEmitterConfig hc = new HTMLEmitterConfig();
HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler();
hc.setImageHandler(imageHandler);
config.setEmitterConfiguration(HTMLRenderOption.OUTPUT_FORMAT_HTML, hc);
ReportEngine engine = new ReportEngine(config);
IReportRunnable report = null;
String reportFilepath = "C:/Workspace/EntireJ/Besuchblatt/reports/new_report.rptdesign";
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(format);
options.setOutputFileName("C:/Workspace/myProject/birtReport" + reportNr + ".pdf");
long startTime = System.currentTimeMillis();
try {
report = engine.openReportDesign(reportFilepath);
}
catch (EngineException e) {
System.err.println("Report " + reportFilepath + " not found!\n");
engine.destroy( );
return;
}
IRunAndRenderTask task = engine.createRunAndRenderTask(report);
task.setRenderOption(options);
task.setParameterValues(parametersMap);
try {
task.run();
return (System.currentTimeMillis() - startTime);
}
catch ( EngineException e1 ) {
System.err.println( "Report " + reportFilepath + " run failed.\n");
System.err.println( e1.toString( ) );
}
engine.destroy( );
有没有办法在我的情况下优化Birt的性能?