-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_speed_tests.py
149 lines (143 loc) · 6.38 KB
/
run_speed_tests.py
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2011 Yesudeep Mangalapilly <[email protected]>
# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from mom.tests.speed import report
setups = [
"from mom.codec.base36 import b36encode; import os; b = os.urandom(256)",
"from mom.codec.base36 import b36decode, b36encode; import os; b = b36encode(os.urandom(256))",
"from mom.codec.base36 import b36encode; import os; b = os.urandom(3079)",
"from mom.codec.base36 import b36decode, b36encode; import os; b = b36encode(os.urandom(3079))",
None,
"from mom.codec.base58 import b58encode; import os; b = os.urandom(3079)",
"from mom.codec._alt_base import b58encode_naive; import os; b = os.urandom(3079)",
"from mom.tests.bitcointools_base58 import b58encode_bitcoin; import os; b = os.urandom(3079)",
"from mom.codec.base58 import b58decode, b58encode; import os; b = b58encode(os.urandom(60))",
"from mom.codec._alt_base import b58decode_naive; from mom.codec.base58 import b58encode; import os; b = b58encode(os.urandom(60))",
"from mom.tests.bitcointools_base58 import b58decode_bitcoin; from mom.codec.base58 import b58encode; import os; b = b58encode(os.urandom(60))",
"from mom.codec.base58 import b58encode; import os; b = os.urandom(60)",
"from mom.codec._alt_base import b58encode_naive; import os; b = os.urandom(60)",
"from mom.tests.bitcointools_base58 import b58encode_bitcoin; import os; b = os.urandom(60)",
None,
"from mom.codec.base62 import b62encode; import os; b = os.urandom(3079)",
"from mom.codec._alt_base import b62encode_naive; import os; b = os.urandom(3079)",
"from mom.codec.base62 import b62decode, b62encode; import os; b = b62encode(os.urandom(60))",
"from mom.codec._alt_base import b62decode_naive; from mom.codec.base62 import b62encode; import os; b = b62encode(os.urandom(60))",
"from mom.codec.base62 import b62encode; import os; b = os.urandom(60)",
"from mom.codec._alt_base import b62encode_naive; import os; b = os.urandom(60)",
None,
"from mom.codec.base85 import b85encode; import os; b = os.urandom(256)",
"from mom.codec.base85 import b85decode, b85encode; import os; b = b85encode(os.urandom(256))",
"from mom.codec.base85 import b85encode; import os; b = os.urandom(3079)",
"from mom.codec.base85 import b85decode, b85encode; import os; b = b85encode(os.urandom(3079))",
None,
"from mom.codec.base85 import ipv6_b85encode; ip = 21932261930451111902915077091070067066",
"from mom.codec._alt_base import ipv6_b85encode_naive; ip = 21932261930451111902915077091070067066",
"from mom.codec.base85 import ipv6_b85decode; from mom.builtins import b; ip = b('4)+k&C#VzJ4br>0wv%Yp')",
"from mom.codec._alt_base import ipv6_b85decode_naive; from mom.builtins import b; ip = b('4)+k&C#VzJ4br>0wv%Yp')",
None,
"from mom.codec.base85 import rfc1924_b85encode; import os; b = os.urandom(256)",
"from mom.codec.base85 import rfc1924_b85decode, rfc1924_b85encode; import os; b = rfc1924_b85encode(os.urandom(256))",
"from mom.codec.base85 import rfc1924_b85encode; import os; b = os.urandom(3079)",
"from mom.codec.base85 import rfc1924_b85decode, rfc1924_b85encode; import os; b = rfc1924_b85encode(os.urandom(3079))",
None,
"from mom.builtins import integer_byte_length; n=1<<4096",
"from mom._alt_builtins import integer_byte_length_word_aligned; n=1<<4096",
"from mom._alt_builtins import integer_byte_length_shift_counting; n=1<<4096",
None,
"from mom.builtins import integer_bit_length; n=1<<4096",
"from mom._alt_builtins import integer_bit_length_word_aligned; n=1<<4096",
"from mom._alt_builtins import integer_bit_length_shift_counting; n=1<<4096",
None,
"from mom.codec.integer import uint_to_bytes; n=1<<4096",
"from mom.codec._alt_integer import uint_to_bytes_simple; n=1<<4096",
"from mom.codec._alt_integer import uint_to_bytes_array_based; n=1<<4096",
"from mom.codec._alt_integer import uint_to_bytes_pycrypto; n=1<<4096",
"from mom.codec._alt_integer import uint_to_bytes_naive; n=1<<4096",
"from mom.codec._alt_integer import uint_to_bytes_naive_array_based; n=1<<4096",
None,
"import os; from mom.codec.integer import bytes_to_uint; b = os.urandom(4003)",
"import os; from mom.codec._alt_integer import bytes_to_uint_naive; b = os.urandom(4003)",
"import os; from mom.codec._alt_integer import bytes_to_uint_simple; b = os.urandom(4003)",
]
statements = [
"b36encode(b)",
"b36decode(b)",
"b36encode(b)",
"b36decode(b)",
None,
"b58encode(b)",
"b58encode_naive(b)",
"b58encode_bitcoin(b)",
"b58decode(b)",
"b58decode_naive(b)",
"b58decode_bitcoin(b)",
"b58encode(b)",
"b58encode_naive(b)",
"b58encode_bitcoin(b)",
None,
"b62encode(b)",
"b62encode_naive(b)",
"b62decode(b)",
"b62decode_naive(b)",
"b62encode(b)",
"b62encode_naive(b)",
None,
"b85encode(b)",
"b85decode(b)",
"b85encode(b)",
"b85decode(b)",
None,
"ipv6_b85encode(ip)",
"ipv6_b85encode_naive(ip)",
"ipv6_b85decode(ip)",
"ipv6_b85decode_naive(ip)",
None,
"rfc1924_b85encode(b)",
"rfc1924_b85decode(b)",
"rfc1924_b85encode(b)",
"rfc1924_b85decode(b)",
None,
"integer_byte_length(n)",
"integer_byte_length_word_aligned(n)",
"integer_byte_length_shift_counting(n)",
None,
"integer_bit_length(n)",
"integer_bit_length_word_aligned(n)",
"integer_bit_length_shift_counting(n)",
None,
"uint_to_bytes(n)",
"uint_to_bytes_simple(n)",
"uint_to_bytes_array_based(n)",
"uint_to_bytes_pycrypto(n)",
"uint_to_bytes_naive(n)",
"uint_to_bytes_naive_array_based(n)",
None,
"bytes_to_uint(b)",
"bytes_to_uint_naive(b)",
"bytes_to_uint_simple(b)",
]
def main(setups, statements):
print("Python %s" % sys.version)
for setup, statement in zip(setups, statements):
if setup is None or statement is None:
print("")
else:
report(statement, setup)
print("\n%s" % ("-" * 100))
if __name__ == "__main__":
main(setups, statements)