SHARE
TWEET

Untitled

a guest Oct 21st, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import gc
  2. import cProfile
  3. import pstats
  4.  
  5. from pyasn1.type import namedtype
  6. from pyasn1.type import univ
  7. from pyasn1.compat.octets import ints2octs, null
  8. from pyasn1.codec.der.decoder import decode as der_decode
  9. from pyasn1.codec.ber.decoder import decode as ber_decode
  10. from pyasn1_modules import pem
  11. from pyasn1_modules import rfc2314
  12.  
  13. gc.disable()
  14.  
  15. asn = univ.Set(
  16.     componentType=namedtype.NamedTypes(
  17.         namedtype.NamedType('place-holder', univ.Null(null)),
  18.         namedtype.OptionalNamedType('first-name', univ.OctetString()),
  19.         namedtype.DefaultedNamedType('age', univ.Integer(33)),
  20.     )
  21. )
  22.  
  23. pem_64 = """\
  24. MIIDATCCAekCAQAwgZkxCzAJBgNVBAYTAlJVMRYwFAYDVQQIEw1Nb3Njb3cgUmVn
  25. aW9uMQ8wDQYDVQQHEwZNb3Njb3cxGjAYBgNVBAoTEVNOTVAgTGFib3JhdG9yaWVz
  26. MQwwCgYDVQQLFANSJkQxFTATBgNVBAMTDHNubXBsYWJzLmNvbTEgMB4GCSqGSIb3
  27. DQEJARYRaW5mb0Bzbm1wbGFicy5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
  28. ggEKAoIBAQC9n2NfGS98JDBmAXQn+vNUyPB3QPYC1cwpX8UMYh9MdAmBZJCnvXrQ
  29. Pp14gNAv6AQKxefmGES1b+Yd+1we9HB8AKm1/8xvRDUjAvy4iO0sqFCPvIfSujUy
  30. pBcfnR7QE2itvyrMxCDSEVnMhKdCNb23L2TptUmpvLcb8wfAMLFsSu2yaOtJysep
  31. oH/mvGqlRv2ti2+E2YA0M7Pf83wyV1XmuEsc9tQ225rprDk2uyshUglkDD2235rf
  32. 0QyONq3Aw3BMrO9ss1qj7vdDhVHVsxHnTVbEgrxEWkq2GkVKh9QReMZ2AKxe40j4
  33. og+OjKXguOCggCZHJyXKxccwqCaeCztbAgMBAAGgIjAgBgkqhkiG9w0BCQIxExMR
  34. U05NUCBMYWJvcmF0b3JpZXMwDQYJKoZIhvcNAQEFBQADggEBAAihbwmN9M2bsNNm
  35. 9KfxqiGMqqcGCtzIlpDz/2NVwY93cEZsbz3Qscc0QpknRmyTSoDwIG+1nUH0vzkT
  36. Nv8sBmp9I1GdhGg52DIaWwL4t9O5WUHgfHSJpPxZ/zMP2qIsdPJ+8o19BbXRlufc
  37. 73c03H1piGeb9VcePIaulSHI622xukI6f4Sis49vkDaoi+jadbEEb6TYkJQ3AMRD
  38. WdApGGm0BePdLqboW1Yv70WRRFFD8sxeT7Yw4qrJojdnq0xMHPGfKpf6dJsqWkHk
  39. b5DRbjil1Zt9pJuF680S9wtBzSi0hsMHXR9TzS7HpMjykL2nmCVY6A78MZapsCzn
  40. GGbx7DI=
  41. """
  42. pem_text = pem.readBase64fromText(pem_64)
  43. pem_spec = rfc2314.CertificationRequest()
  44.  
  45.  
  46. examples = dict(
  47.     small_scalar=(
  48.         ints2octs((1, 1, 0)),
  49.         ber_decode,
  50.         {}
  51.     ),
  52.     small_schemaless=(
  53.         ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107,
  54.                    32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0,
  55.                    0)),
  56.         ber_decode,
  57.         {}
  58.     ),
  59.     small_with_schema=(
  60.         ints2octs((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107,
  61.                    32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)),
  62.         ber_decode,
  63.         {"asn1Spec": asn}
  64.     ),
  65.     large_with_schema=(
  66.         pem_text,
  67.         der_decode,
  68.         {"asn1Spec": pem_spec}
  69.     )
  70. )
  71.  
  72. TIMES = 30000
  73.  
  74. if __name__ == "__main__":
  75.  
  76.     for name, triplet in examples.items():
  77.  
  78.         print('Pondering ', name)
  79.  
  80.         substrate, method, kwargs = triplet
  81.  
  82.         pr = cProfile.Profile()
  83.         pr.enable()
  84.  
  85.         for _ in range(TIMES):
  86.             method(substrate, **kwargs)
  87.  
  88.         pr.disable()
  89.         st = pstats.Stats(pr)
  90.         st.strip_dirs()
  91.         st.sort_stats('cumtime')
  92.         st.print_stats(.3)
  93.  
  94.         print('-' * 80)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top