@@ -55,31 +55,34 @@ def setup(workdir):
55
55
# Creating working directory and populating it with test files
56
56
RNPDIR = path .join (WORKDIR , '.rnp' )
57
57
GPGDIR = path .join (WORKDIR , '.gpg' )
58
- os .mkdir (RNPDIR , 0700 )
59
- os .mkdir (GPGDIR , 0700 )
58
+ os .mkdir (RNPDIR , 0o700 )
59
+ os .mkdir (GPGDIR , 0o700 )
60
60
61
61
# Generating key
62
62
pipe = pswd_pipe (PASSWORD )
63
- params = ['--homedir' , RNPDIR , '--pass-fd' , str (pipe ), '--userid' , 'performance@rnp' , '--generate-key' ]
63
+ params = ['--homedir' , RNPDIR , '--pass-fd' , str (pipe ), '--userid' , 'performance@rnp' ,
64
+ '--generate-key' ]
64
65
# Run key generation
65
66
ret , out , err = run_proc (RNPK , params )
66
67
os .close (pipe )
67
68
68
69
# Importing keys to GnuPG so it can build trustdb and so on
69
- ret , out , err = run_proc (GPG , ['--batch' , '--passphrase' , '' , '--homedir' , GPGDIR , '--import' , path .join (RNPDIR , 'pubring.gpg' ), path .join (RNPDIR , 'secring.gpg' )])
70
+ ret , out , err = run_proc (GPG , ['--batch' , '--passphrase' , '' , '--homedir' , GPGDIR ,
71
+ '--import' , path .join (RNPDIR , 'pubring.gpg' ),
72
+ path .join (RNPDIR , 'secring.gpg' )])
70
73
71
74
# Generating small file for tests
72
- SMALLSIZE = 3312 ;
73
- st = 'lorem ipsum dol ' * (SMALLSIZE / 16 )
75
+ SMALLSIZE = 3312
76
+ st = 'lorem ipsum dol ' * (SMALLSIZE // 16 + 1 )
74
77
with open (path .join (WORKDIR , SMALLFILE ), 'w+' ) as small_file :
75
78
small_file .write (st )
76
79
77
80
# Generating large file for tests
78
- print 'Generating large file of size {}' .format (size_to_readable (LARGESIZE ))
81
+ print ( 'Generating large file of size {}' .format (size_to_readable (LARGESIZE ) ))
79
82
80
- st = '0123456789ABCDEF' * (1024 / 16 )
83
+ st = '0123456789ABCDEF' * (1024 // 16 )
81
84
with open (path .join (WORKDIR , LARGEFILE ), 'w' ) as fd :
82
- for i in range (0 , LARGESIZE / 1024 - 1 ):
85
+ for i in range (0 , LARGESIZE // 1024 ):
83
86
fd .write (st )
84
87
85
88
def run_iterated (iterations , func , src , dst , * args ):
@@ -96,28 +99,34 @@ def run_iterated(iterations, func, src, dst, *args):
96
99
return res
97
100
98
101
def rnp_symencrypt_file (src , dst , cipher , zlevel = 6 , zalgo = 'zip' , armor = False ):
99
- params = ['--homedir' , RNPDIR , '--password' , PASSWORD , '--cipher' , cipher , '-z' , str (zlevel ), '--' + zalgo , '-c' , src , '--output' , dst ]
102
+ params = ['--homedir' , RNPDIR , '--password' , PASSWORD , '--cipher' , cipher ,
103
+ '-z' , str (zlevel ), '--' + zalgo , '-c' , src , '--output' , dst ]
100
104
if armor :
101
105
params += ['--armor' ]
102
106
ret = run_proc_fast (RNP , params )
103
107
if ret != 0 :
104
108
raise_err ('rnp symmetric encryption failed' )
105
109
106
110
def rnp_decrypt_file (src , dst ):
107
- ret = run_proc_fast (RNP , ['--homedir' , RNPDIR , '--password' , PASSWORD , '--decrypt' , src , '--output' , dst ])
111
+ ret = run_proc_fast (RNP , ['--homedir' , RNPDIR , '--password' , PASSWORD , '--decrypt' , src ,
112
+ '--output' , dst ])
108
113
if ret != 0 :
109
114
raise_err ('rnp decryption failed' )
110
115
111
116
def gpg_symencrypt_file (src , dst , cipher = 'AES' , zlevel = 6 , zalgo = 1 , armor = False ):
112
- params = ['--homedir' , GPGDIR , '-c' , '-z' , str (zlevel ), '--s2k-count' , '524288' , '--compress-algo' , str (zalgo ), '--batch' , '--passphrase' , PASSWORD , '--cipher-algo' , cipher , '--output' , dst , src ]
117
+ params = ['--homedir' , GPGDIR , '-c' , '-z' , str (zlevel ), '--s2k-count' , '524288' ,
118
+ '--compress-algo' , str (zalgo ), '--batch' , '--passphrase' , PASSWORD ,
119
+ '--cipher-algo' , cipher , '--output' , dst , src ]
113
120
if armor :
114
121
params .insert (2 , '--armor' )
115
122
ret = run_proc_fast (GPG , params )
116
123
if ret != 0 :
117
124
raise_err ('gpg symmetric encryption failed for cipher ' + cipher )
118
125
119
126
def gpg_decrypt_file (src , dst , keypass ):
120
- ret = run_proc_fast (GPG , ['--homedir' , GPGDIR , '--pinentry-mode=loopback' , '--batch' , '--yes' , '--passphrase' , keypass , '--trust-model' , 'always' , '-o' , dst , '-d' , src ])
127
+ ret = run_proc_fast (GPG , ['--homedir' , GPGDIR , '--pinentry-mode=loopback' , '--batch' ,
128
+ '--yes' , '--passphrase' , keypass , '--trust-model' , 'always' ,
129
+ '-o' , dst , '-d' , src ])
121
130
if ret != 0 :
122
131
raise_err ('gpg decryption failed' )
123
132
@@ -132,27 +141,33 @@ def print_test_results(fsize, rnptime, gpgtime, operation):
132
141
133
142
if rnpruns >= gpgruns :
134
143
percents = (rnpruns - gpgruns ) / gpgruns * 100
135
- logging .info ('{:<30}: RNP is {:>3.0f}% FASTER then GnuPG ({})' .format (operation , percents , runstr ))
144
+ logging .info ('{:<30}: RNP is {:>3.0f}% FASTER then GnuPG ({})' .format (
145
+ operation , percents , runstr ))
136
146
else :
137
147
percents = (gpgruns - rnpruns ) / gpgruns * 100
138
- logging .info ('{:<30}: RNP is {:>3.0f}% SLOWER then GnuPG ({})' .format (operation , percents , runstr ))
148
+ logging .info ('{:<30}: RNP is {:>3.0f}% SLOWER then GnuPG ({})' .format (
149
+ operation , percents , runstr ))
139
150
else :
140
151
rnpspeed = fsize / 1024.0 / 1024.0 / rnptime
141
152
gpgspeed = fsize / 1024.0 / 1024.0 / gpgtime
142
153
spdstr = '{:.2f} MB/sec vs {:.2f} MB/sec' .format (rnpspeed , gpgspeed )
143
154
144
155
if rnpspeed >= gpgspeed :
145
156
percents = (rnpspeed - gpgspeed ) / gpgspeed * 100
146
- logging .info ('{:<30}: RNP is {:>3.0f}% FASTER then GnuPG ({})' .format (operation , percents , spdstr ))
157
+ logging .info ('{:<30}: RNP is {:>3.0f}% FASTER then GnuPG ({})' .format (
158
+ operation , percents , spdstr ))
147
159
else :
148
160
percents = (gpgspeed - rnpspeed ) / gpgspeed * 100
149
- logging .info ('{:<30}: RNP is {:>3.0f}% SLOWER then GnuPG ({})' .format (operation , percents , spdstr ))
161
+ logging .info ('{:<30}: RNP is {:>3.0f}% SLOWER then GnuPG ({})' .format (
162
+ operation , percents , spdstr ))
150
163
151
164
def get_file_params (filetype ):
152
165
if filetype == 'small' :
153
- infile , outfile , iterations , fsize = (SMALLFILE , SMALLFILE + '.gpg' , SMALL_ITERATIONS , SMALLSIZE )
166
+ infile , outfile , iterations , fsize = (SMALLFILE , SMALLFILE + '.gpg' ,
167
+ SMALL_ITERATIONS , SMALLSIZE )
154
168
else :
155
- infile , outfile , iterations , fsize = (LARGEFILE , LARGEFILE + '.gpg' , LARGE_ITERATIONS , LARGESIZE )
169
+ infile , outfile , iterations , fsize = (LARGEFILE , LARGEFILE + '.gpg' ,
170
+ LARGE_ITERATIONS , LARGESIZE )
156
171
157
172
infile = path .join (WORKDIR , infile )
158
173
rnpout = path .join (WORKDIR , outfile + '.rnp' )
@@ -172,8 +187,10 @@ def small_file_symmetric_encryption(self):
172
187
'''
173
188
infile , rnpout , gpgout , iterations , fsize = get_file_params ('small' )
174
189
for armor in [False , True ]:
175
- tmrnp = run_iterated (iterations , rnp_symencrypt_file , infile , rnpout , 'AES128' , 0 , 'zip' , armor )
176
- tmgpg = run_iterated (iterations , gpg_symencrypt_file , infile , gpgout , 'AES128' , 0 , 1 , armor )
190
+ tmrnp = run_iterated (iterations , rnp_symencrypt_file , infile , rnpout ,
191
+ 'AES128' , 0 , 'zip' , armor )
192
+ tmgpg = run_iterated (iterations , gpg_symencrypt_file , infile , gpgout ,
193
+ 'AES128' , 0 , 1 , armor )
177
194
testname = 'ENCRYPT-SMALL-{}' .format ('ARMOR' if armor else 'BINARY' )
178
195
print_test_results (fsize , tmrnp , tmgpg , testname )
179
196
@@ -183,8 +200,10 @@ def large_file_symmetric_encryption(self):
183
200
'''
184
201
infile , rnpout , gpgout , iterations , fsize = get_file_params ('large' )
185
202
for cipher in ['AES128' , 'AES192' , 'AES256' , 'TWOFISH' , 'BLOWFISH' , 'CAST5' , 'CAMELLIA128' , 'CAMELLIA192' , 'CAMELLIA256' ]:
186
- tmrnp = run_iterated (iterations , rnp_symencrypt_file , infile , rnpout , cipher , 0 , 'zip' , False )
187
- tmgpg = run_iterated (iterations , gpg_symencrypt_file , infile , gpgout , cipher , 0 , 1 , False )
203
+ tmrnp = run_iterated (iterations , rnp_symencrypt_file , infile , rnpout ,
204
+ cipher , 0 , 'zip' , False )
205
+ tmgpg = run_iterated (iterations , gpg_symencrypt_file , infile , gpgout ,
206
+ cipher , 0 , 1 , False )
188
207
testname = 'ENCRYPT-{}-BINARY' .format (cipher )
189
208
print_test_results (fsize , tmrnp , tmgpg , testname )
190
209
@@ -193,7 +212,8 @@ def large_file_armored_encryption(self):
193
212
Large file armored encryption
194
213
'''
195
214
infile , rnpout , gpgout , iterations , fsize = get_file_params ('large' )
196
- tmrnp = run_iterated (iterations , rnp_symencrypt_file , infile , rnpout , 'AES128' , 0 , 'zip' , True )
215
+ tmrnp = run_iterated (iterations , rnp_symencrypt_file , infile , rnpout ,
216
+ 'AES128' , 0 , 'zip' , True )
197
217
tmgpg = run_iterated (iterations , gpg_symencrypt_file , infile , gpgout , 'AES128' , 0 , 1 , True )
198
218
print_test_results (fsize , tmrnp , tmgpg , 'ENCRYPT-LARGE-ARMOR' )
199
219
@@ -217,7 +237,8 @@ def large_file_symmetric_decryption(self):
217
237
'''
218
238
infile , rnpout , gpgout , iterations , fsize = get_file_params ('large' )
219
239
inenc = infile + '.enc'
220
- for cipher in ['AES128' , 'AES192' , 'AES256' , 'TWOFISH' , 'BLOWFISH' , 'CAST5' , 'CAMELLIA128' , 'CAMELLIA192' , 'CAMELLIA256' ]:
240
+ for cipher in ['AES128' , 'AES192' , 'AES256' , 'TWOFISH' , 'BLOWFISH' , 'CAST5' ,
241
+ 'CAMELLIA128' , 'CAMELLIA192' , 'CAMELLIA256' ]:
221
242
gpg_symencrypt_file (infile , inenc , cipher , 0 , 1 , False )
222
243
tmrnp = run_iterated (iterations , rnp_decrypt_file , inenc , rnpout )
223
244
tmgpg = run_iterated (iterations , gpg_decrypt_file , inenc , gpgout , PASSWORD )
@@ -266,11 +287,14 @@ def large_file_armored_decryption(self):
266
287
help = "Name of the comma-separated benchmarks to run" , metavar = "benchmarks" )
267
288
parser .add_argument ("-w" , "--workdir" , dest = "workdir" ,
268
289
help = "Working directory to use" , metavar = "workdir" )
269
- parser .add_argument ("-l" , "--list" , help = "Print list of available benchmarks and exit" , action = "store_true" )
290
+ parser .add_argument ("-l" , "--list" , help = "Print list of available benchmarks and exit" ,
291
+ action = "store_true" )
270
292
args = parser .parse_args ()
271
293
272
294
# get list of benchamrks to run
273
- bench_methods = [ x [0 ] for x in inspect .getmembers (Benchmark ,predicate = inspect .ismethod ) if not x [0 ].startswith ("_" ) ]
295
+ bench_methods = [ x [0 ] for x in inspect .getmembers (Benchmark ,
296
+ predicate = lambda x : inspect .ismethod (x ) or inspect .isfunction (x ))]
297
+ print (bench_methods )
274
298
275
299
if args .list :
276
300
for name in bench_methods :
0 commit comments