Skip to content

@visik7 /gist:4961145
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
import java.io.IOException;
import org.apache.commons.lang3.time.StopWatch;
import org.joda.time.DateTime;
import org.joda.time.Instant;
import org.joda.time.Interval;
import de.intarsys.pdf.content.common.CSCreator;
import de.intarsys.pdf.cos.COSBasedObject;
import de.intarsys.pdf.encoding.WinAnsiEncoding;
import de.intarsys.pdf.font.PDFont;
import de.intarsys.pdf.font.PDFontType1;
import de.intarsys.pdf.font.PDFontType3;
import de.intarsys.pdf.font.outlet.FontFactoryException;
import de.intarsys.pdf.font.outlet.FontOutlet;
import de.intarsys.pdf.font.outlet.FontQuery;
import de.intarsys.pdf.font.outlet.IFontFactory;
import de.intarsys.pdf.parser.COSLoadException;
import de.intarsys.pdf.pd.PDDocument;
import de.intarsys.pdf.pd.PDPage;
import de.intarsys.pdf.pd.PDPageTree;
import de.intarsys.pdf.st.EnumWriteMode;
import de.intarsys.tools.locator.FileLocator;
import de.intarsys.tools.locator.ILocator;
public class SpeedTestJpod {
private PDFontType1 font;
/**
* @param args
* @throws IOException
* @throws FontFactoryException
* @throws COSLoadException
*/
public static void main(String[] args) throws IOException,
FontFactoryException, COSLoadException {
StopWatch runTestTime;
int pages = 10000000;
runTestTime = runTest(pages,1000,3000,10000,50000);
System.out.println("Total time: " +runTestTime.toSplitString()+ " "+(pages*1.0d/runTestTime.getTime())*1000+" p/s");
}
private static StopWatch runTest(int i, int j, int k, int l, int m) throws FontFactoryException, IOException, COSLoadException {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
new SpeedTestJpod().run(i,j,k,l,m);
stopWatch.split();
stopWatch.stop();
return stopWatch;
}
private void run(int iterations, int nodeEvery, int saveEvery, int sampleEvery, int resetEvery) throws FontFactoryException, IOException, COSLoadException {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
PDDocument document = PDDocument.createNew();
try {
document.setAuthor(" S.p.A.");
document.setCreator("2pdf");
ILocator locator = new FileLocator("test.pdf");
PDPageTree newNode = null;
PDFont font = null;
for (int i = 0; i <= iterations; i++) {
document.setWriteModeHint(EnumWriteMode.INCREMENTAL);
if(i % nodeEvery == 0) {
newNode = (PDPageTree) PDPageTree.META.createNew();
document.addPageNode(newNode);
font = getFont(document);
}
PDPage page = (PDPage) PDPage.META.createNew();
newNode.addNode(page);
CSCreator creator = CSCreator.createNew(page);
creator.textSetFont(null, font, 20f);
creator.textLineMoveTo(100, 700);
creator.textShow("Hello, world.");
//creator.flush();
creator.close();
if(i % sampleEvery == 0) {
stopWatch.split();
stopWatch.stop();
long partTime = stopWatch.getTime();
String a = (sampleEvery*1.0d/partTime)*1000+" p/s ";
System.err.println(stopWatch.toSplitString()+" "+a);
System.err.println(i/sampleEvery);
stopWatch.reset();
stopWatch.start();
}
if(i % saveEvery == 0) {
document.save(locator);
}
if(i % resetEvery == 0) {
//System.gc();
//document.close();
//document = PDDocument.createFromLocator(new FileLocator("test.pdf"));
}
}
} finally {
document.close();
document = null;
}
}
private PDFont getFont(PDDocument document) throws FontFactoryException {
//IFontFactory factory = FontOutlet.get().lookupFontFactory(document);
//FontQuery fontquery = new FontQuery("Arial", "");
//PDFont font = factory.getFont(fontquery);
if(font==null)
font = PDFontType1.createNew(PDFontType1.FONT_Helvetica);
return font;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.