blob: 498e6a05ee665d6e8512ecaffaf02699b3b01160 [file] [log] [blame]
Sybren A. Stüvel360d0422011-08-10 10:52:591#!/usr/bin/env python
Roy Kokkelkoren0659aac2015-10-25 15:12:112# Copyright 2011 Sybren A. Stüvel <[email protected]>
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
Sybren A. Stüvel3934ab42016-02-05 15:01:208# https://www.apache.org/licenses/LICENSE-2.0
Roy Kokkelkoren0659aac2015-10-25 15:12:119#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
Sybren A. Stüvel360d0422011-08-10 10:52:5915
16import time
17import rsa
18
19poolsize = 8
20accurate = True
21
Sybren A. Stüvel360d0422011-08-10 10:52:5922
Sybren A. Stüveld3d10342016-01-22 10:36:0623def run_speed_test(bitsize):
Sybren A. Stüvel360d0422011-08-10 10:52:5924 iterations = 0
25 start = end = time.time()
26
27 # At least a number of iterations, and at least 2 seconds
28 while iterations < 10 or end - start < 2:
29 iterations += 1
30 rsa.newkeys(bitsize, accurate=accurate, poolsize=poolsize)
31 end = time.time()
32
33 duration = end - start
34 dur_per_call = duration / iterations
35
Sybren A. Stüveld3d10342016-01-22 10:36:0636 print('%5i bit: %9.3f sec. (%i iterations over %.1f seconds)' %
37 (bitsize, dur_per_call, iterations, duration))
38
Sybren A. Stüvel360d0422011-08-10 10:52:5939
Sybren A. Stüvelf95dbb72016-01-22 11:19:0940if __name__ == '__main__':
41 for bitsize in (128, 256, 384, 512, 1024, 2048, 3072, 4096):
42 run_speed_test(bitsize)