Add benchmark
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.idea
|
||||
*.pdf
|
||||
*.pdf.*
|
||||
!benchmark.pdf
|
@@ -98,7 +98,7 @@ func TestSignPDF(t *testing.T) {
|
||||
|
||||
certificate_data_block, _ := pem.Decode([]byte(signCertPem))
|
||||
if certificate_data_block == nil {
|
||||
t.Errorf("failed to parse PEM block containing the certificate", err.Error())
|
||||
t.Errorf("failed to parse PEM block containing the certificate")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -162,3 +162,62 @@ func TestSignPDF(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSignPDF(b *testing.B) {
|
||||
certificate_data_block, _ := pem.Decode([]byte(signCertPem))
|
||||
if certificate_data_block == nil {
|
||||
b.Errorf("failed to parse PEM block containing the certificate")
|
||||
return
|
||||
}
|
||||
|
||||
cert, err := x509.ParseCertificate(certificate_data_block.Bytes)
|
||||
if err != nil {
|
||||
b.Errorf("%s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
key_data_block, _ := pem.Decode([]byte(signKeyPem))
|
||||
if key_data_block == nil {
|
||||
b.Errorf("failed to parse PEM block containing the private key")
|
||||
return
|
||||
}
|
||||
|
||||
pkey, err := x509.ParsePKCS1PrivateKey(key_data_block.Bytes)
|
||||
if err != nil {
|
||||
b.Errorf("%s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
certificate_chains := make([][]*x509.Certificate, 0)
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
err := SignFile("../testfiles/benchmark.pdf", "../testfiles/benchmark.pdf.tmp", SignData{
|
||||
Signature: SignDataSignature{
|
||||
Info: SignDataSignatureInfo{
|
||||
Name: "Jeroen Bobbeldijk",
|
||||
Location: "Rotterdam",
|
||||
Reason: "Test",
|
||||
ContactInfo: "Geen",
|
||||
Date: time.Now().Local(),
|
||||
},
|
||||
CertType: 2,
|
||||
Approval: false,
|
||||
},
|
||||
Signer: pkey,
|
||||
Certificate: cert,
|
||||
CertificateChains: certificate_chains,
|
||||
TSA: TSA{
|
||||
URL: "http://aatl-timestamp.globalsign.com/tsa/aohfewat2389535fnasgnlg5m23",
|
||||
},
|
||||
RevocationData: revocation.InfoArchival{},
|
||||
RevocationFunction: DefaultEmbedRevocationStatusFunction,
|
||||
})
|
||||
|
||||
os.Remove("../testfiles/benchmark.pdf.tmp")
|
||||
|
||||
if err != nil {
|
||||
b.Errorf("%s: %s", "benchmark.pdf", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
201
testfiles/benchmark.pdf
Normal file
201
testfiles/benchmark.pdf
Normal file
@@ -0,0 +1,201 @@
|
||||
%PDF-2.0
|
||||
|
||||
1 0 obj
|
||||
<<
|
||||
/Type /Catalog
|
||||
/Metadata 2 0 R
|
||||
/Pages 3 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
2 0 obj
|
||||
<<
|
||||
/Length 2351
|
||||
/Type /Metadata
|
||||
/Subtype /XML
|
||||
>>
|
||||
stream
|
||||
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Insert XMP tool name here.'>
|
||||
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
|
||||
<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
|
||||
<pdf:Producer>Datalogics - example producer program name here</pdf:Producer>
|
||||
<pdf:Copyright>Copyright 2017 PDF Association</pdf:Copyright>
|
||||
<pdf:Keywords>PDF 2.0 sample example</pdf:Keywords>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="" xmlns:xap="http://ns.adobe.com/xap/1.0/">
|
||||
<xap:CreateDate>2017-05-24T10:30:11Z</xap:CreateDate>
|
||||
<xap:MetadataDate>2017-07-11T07:55:11Z</xap:MetadataDate>
|
||||
<xap:ModifyDate>2017-07-11T07:55:11Z</xap:ModifyDate>
|
||||
<xap:CreatorTool>Datalogics - example creator tool name here</xap:CreatorTool>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<dc:format>application/pdf</dc:format>
|
||||
<dc:title>
|
||||
<rdf:Alt>
|
||||
<rdf:li xml:lang="x-default">A simple PDF 2.0 example file</rdf:li>
|
||||
</rdf:Alt>
|
||||
</dc:title>
|
||||
<dc:creator>
|
||||
<rdf:Seq>
|
||||
<rdf:li>Datalogics Incorporated</rdf:li>
|
||||
</rdf:Seq>
|
||||
</dc:creator>
|
||||
<dc:description>
|
||||
<rdf:Alt>
|
||||
<rdf:li xml:lang="x-default">Demonstration of a simple PDF 2.0 file.</rdf:li>
|
||||
</rdf:Alt>
|
||||
</dc:description>
|
||||
<dc:rights>
|
||||
<rdf:Alt>
|
||||
<rdf:li xml:lang="x-default">Copyright 2017 PDF Association. Licensed to the public under Creative Commons Attribution-ShareAlike 4.0 International license.</rdf:li>
|
||||
</rdf:Alt>
|
||||
</dc:rights>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="" xmlns:xapRights="http://ns.adobe.com/xap/1.0/rights/">
|
||||
<xapRights:Marked>True</xapRights:Marked>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="" xmlns:cc="http://creativecommons.org/ns#">
|
||||
<cc:license rdf:resource="https://creativecommons.org/licenses/sa/4.0/" />
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="" xmlns:xapMM="http://ns.adobe.com/xap/1.0/mm/">
|
||||
<xapMM:DocumentID>uuid:3eef2166-8332-abb4-3d31-77334578873f</xapMM:DocumentID>
|
||||
<xapMM:InstanceID>uuid:991bcce7-ee70-11a3-91aa-77bbe2181fd8</xapMM:InstanceID>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
endstream
|
||||
endobj
|
||||
|
||||
3 0 obj
|
||||
<<
|
||||
/Type /Pages
|
||||
/Kids [4 0 R]
|
||||
/Count 1
|
||||
>>
|
||||
endobj
|
||||
|
||||
4 0 obj
|
||||
<<
|
||||
/Type /Page
|
||||
/Parent 3 0 R
|
||||
/MediaBox [0 0 612 396]
|
||||
/Contents [5 0 R 6 0 R]
|
||||
/Resources <<
|
||||
/Font << /F1 7 0 R >>
|
||||
>>
|
||||
>>
|
||||
endobj
|
||||
|
||||
5 0 obj
|
||||
<< /Length 744 >>
|
||||
stream
|
||||
% Save the current graphic state
|
||||
q
|
||||
|
||||
% Draw a black line segment, using the default line width.
|
||||
150 250 m
|
||||
150 350 l
|
||||
S
|
||||
|
||||
% Draw a thicker, dashed line segment.
|
||||
4 w % Set line width to 4 points
|
||||
[4 6] 0 d % Set dash pattern to 4 units on, 6 units off
|
||||
150 250 m
|
||||
400 250 l
|
||||
S
|
||||
[] 0 d % Reset dash pattern to a solid line
|
||||
1 w % Reset line width to 1 unit
|
||||
|
||||
% Draw a rectangle with a 1-unit red border, filled with light blue.
|
||||
1.0 0.0 0.0 RG % Red for stroke color
|
||||
0.5 0.75 1.0 rg % Light blue for fill color
|
||||
200 300 50 75 re
|
||||
B
|
||||
|
||||
% Draw a curve filled with gray and with a colored border.
|
||||
0.5 0.1 0.2 RG
|
||||
0.7 g
|
||||
300 300 m
|
||||
300 400 400 400 400 300 c
|
||||
b
|
||||
|
||||
% Restore the graphic state to what it was at the beginning of this stream
|
||||
Q
|
||||
|
||||
endstream
|
||||
endobj
|
||||
|
||||
6 0 obj
|
||||
<< /Length 166 >>
|
||||
stream
|
||||
% A text block that shows "Hello World"
|
||||
% No color is set, so this defaults to black in DeviceGray colorspace
|
||||
BT
|
||||
/F1 24 Tf
|
||||
100 100 Td
|
||||
(Hello World) Tj
|
||||
ET
|
||||
endstream
|
||||
endobj
|
||||
|
||||
7 0 obj
|
||||
<<
|
||||
/Type /Font
|
||||
/Subtype /Type1
|
||||
/BaseFont /Helvetica
|
||||
/FirstChar 33
|
||||
/LastChar 126
|
||||
/Widths 8 0 R
|
||||
/FontDescriptor 9 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
8 0 obj
|
||||
[ 278 355 556 556 889 667 222 333 333 389 584 278 333 278 278 556
|
||||
556 556 556 556 556 556 556 556 556 278 278 584 584 584 556 1015
|
||||
667 667 722 722 667 611 778 722 278 500 667 556 833 722 778 667
|
||||
778 722 667 611 722 667 944 667 667 611 278 278 278 469 556 222
|
||||
556 556 500 556 556 278 556 556 222 222 500 222 833 556 556 556
|
||||
556 333 500 278 556 500 722 500 500 500 334 260 334 584 ]
|
||||
endobj
|
||||
|
||||
% This FontDescriptor contains only the required entries for PDF 2.0
|
||||
% for unembedded standard 14 fonts that contain Latin characters
|
||||
9 0 obj
|
||||
<<
|
||||
/Type /FontDescriptor
|
||||
/FontName /Helvetica
|
||||
/Flags 32
|
||||
/FontBBox [ -166 -225 1000 931 ]
|
||||
/ItalicAngle 0
|
||||
/Ascent 718
|
||||
/Descent -207
|
||||
/CapHeight 718
|
||||
/StemV 88
|
||||
/MissingWidth 0
|
||||
>>
|
||||
endobj
|
||||
|
||||
% The object cross-reference table. The first entry
|
||||
% denotes the start of PDF data in this file.
|
||||
xref
|
||||
0 10
|
||||
0000000000 65535 f
|
||||
0000000012 00000 n
|
||||
0000000092 00000 n
|
||||
0000002543 00000 n
|
||||
0000002615 00000 n
|
||||
0000002778 00000 n
|
||||
0000003583 00000 n
|
||||
0000003807 00000 n
|
||||
0000003968 00000 n
|
||||
0000004520 00000 n
|
||||
trailer
|
||||
<<
|
||||
/Size 10
|
||||
/Root 1 0 R
|
||||
/ID [ <31c7a8a269e4c59bc3cd7df0dabbf388><31c7a8a269e4c59bc3cd7df0dabbf388> ]
|
||||
>>
|
||||
startxref
|
||||
4847
|
||||
%%EOF
|
Reference in New Issue
Block a user