]> Cypherpunks.ru repositories - pyderasn.git/blob - doc/performance.rst
New performance measurements
[pyderasn.git] / doc / performance.rst
1 .. _performance:
2
3 Performance
4 ===========
5
6 .. contents::
7
8 Performance is compared between ``pyderasn==6.1``, ``pyasn1==0.4.8`` and
9 ``asn1crypto==1.3.0``. Decode CACert.org's CRL (2019-02-08 state, 8.72
10 MiB), encode it, pickle decoded structure and unpickle it. Machine is
11 Intel Core i5-6200U 2.3 GHz, 8 GB RAM, FreeBSD 12.0 amd64, Python 2.7.15
12 and Python 3.6.6 from native FreeBSD ports.
13
14 Code
15 ----
16
17 pyasn1::
18
19     from pyasn1.codec.der.decoder import decode as der_decoder
20     from pyasn1.codec.der.encoder import encode as der_encoder
21     from pyasn1_modules.rfc5280 import CertificateList
22     with open("revoke.crl", "rb") as fd:
23         raw = fd.read()
24     start = time()
25     crl, _ = der_decoder(raw, asn1Spec=CertificateList())
26     print("decode", time() - start)
27     del raw
28     gc.collect()
29     start = time()
30     der_encoder(c)
31     print("encode", time() - start)
32     # pyasn1 objects are not picklable
33
34 asn1crypto::
35
36     from asn1crypto.crl import CertificateList
37     with open("revoke.crl", "rb") as fd:
38         raw = fd.read()
39     start = time()
40     crl = CertificateList.load(raw)
41     c.native  # full decoding and Python representation requires that
42     print("decode", time() - start)
43     del raw
44     gc.collect()
45     start = time()
46     crl.dump(force=True)  # forced DER encoding
47     print("encode", time() - start)
48     start = time()
49     raw = pickle.dumps(crl)
50     print("dumps", time() - start)
51     del crl
52     gc.collect()
53     print(len(raw))
54     start = time()
55     pickle.loads(raw)
56     print("loads", time() - start)
57
58 pyderasn::
59
60     from tests.test_crl import CertificateList
61     with open("revoke.crl", "rb") as fd:
62         raw = fd.read()
63     start = time()
64     crl = CertificateList().decod(raw)
65     print("decode", time() - start)
66     del raw
67     gc.collect()
68     start = time()
69     crl.encode()
70     print("encode", time() - start)
71     start = time()
72     raw = pickle.dumps(crl)
73     print("dumps", time() - start)
74     del crl
75     gc.collect()
76     print(len(raw))
77     start = time()
78     pickle.loads(raw)
79     print("loads", time() - start)
80
81 Also there are `cythonized <https://cython.org/>`__ asn1crypto and
82 pyderasn versions, made using ``Cython==0.29.14``,
83 ``FreeBSD clang version 6.0.1 (tags/RELEASE_601/final 335540) (based on
84 LLVM 6.0.1)``, ``CFLAGS=-O2`` and Python 3 mode.
85
86 DER
87 ---
88
89 .. list-table::
90    :header-rows: 1
91
92    * - Library
93      - Decode time, sec (Py36/Py27)
94      - Encode time, sec (Py36/Py27)
95      - Memory used, MiB (Py36/Py27)
96    * - pyasn1
97      - 1353 / 1400
98      - 37.5 / 36.7
99      - 1645 / 3296
100    * - asn1crypto
101      - 27.5 / 38
102      - 25.7 / 28
103      - 876 / 1742
104    * - cython asn1crypto
105      - 15.6 / N/A
106      - 15.8 / N/A
107      - 880 / N/A
108    * - pyderasn
109      - 33.2 / 33.4
110      - 7.6 / 7.4
111      - 560 / 516
112    * - cython pyderasn
113      - 23 / N/A
114      - 5.9 / N/A
115      - 561 / N/A
116
117 asn1crypto performs slightly better (with higher memory cost), but pay
118 attention that it contains **much** less data for all objects (like
119 offsets, sizes, etc) and it is not strict at all, passing possibly
120 invalid DER structures! Also there are plenty of other :ref:`features`
121 it lacks.
122
123 pickle
124 ------
125
126 pyasn1 objects are not pickable.
127
128 .. list-table::
129    :header-rows: 1
130
131    * - Library
132      - dumps time, sec (Py36/Py27)
133      - loads time, sec (Py36/Py27)
134      - Memory used, MiB (Py36/Py27)
135      - Size, MiB (Py36/Py27)
136    * - asn1crypto
137      - 7.9 / 145
138      - 8.3 / 91.4
139      - 2474 / 4944
140      - 174.8 / 373
141    * - pyderasn
142      - 82 / 244
143      - 17 / 77.8
144      - 3010 / 4372
145      - 110.5 / 248.6