blob: 498e6a05ee665d6e8512ecaffaf02699b3b01160 [file] [log] [blame]
Sybren A. Stüvel360d0422011-08-10 12:52:59 +02001#!/usr/bin/env python
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +01002# Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu>
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 16:01:20 +01008# https://www.apache.org/licenses/LICENSE-2.0
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +01009#
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 12:52:59 +020015
16import time
17import rsa
18
19poolsize = 8
20accurate = True
21
Sybren A. Stüvel360d0422011-08-10 12:52:59 +020022
Sybren A. Stüveld3d10342016-01-22 11:36:06 +010023def run_speed_test(bitsize):
Sybren A. Stüvel360d0422011-08-10 12:52:59 +020024 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 11:36:06 +010036 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 12:52:59 +020039
Sybren A. Stüvelf95dbb72016-01-22 12:19:09 +010040if __name__ == '__main__':
41 for bitsize in (128, 256, 384, 512, 1024, 2048, 3072, 4096):
42 run_speed_test(bitsize)