Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:4961145
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
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.