blob: 616391653cd57551894965e20879851d1b2d327a [file] [log] [blame]
Sybren A. Stüvel360d0422011-08-10 12:52:59 +02001#!/usr/bin/env python
Sybren A. Stüvel9d2cd9a2015-11-05 19:53:38 +00002# -*- coding: utf-8 -*-
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +01003#
4# Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu>
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
Sybren A. Stüvel3934ab42016-02-05 16:01:20 +010010# https://www.apache.org/licenses/LICENSE-2.0
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +010011#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
Sybren A. Stüvel360d0422011-08-10 12:52:59 +020017
18import time
19import rsa
20
21poolsize = 8
22accurate = True
23
Sybren A. Stüvel360d0422011-08-10 12:52:59 +020024
Sybren A. Stüveld3d10342016-01-22 11:36:06 +010025def run_speed_test(bitsize):
Sybren A. Stüvel360d0422011-08-10 12:52:59 +020026 iterations = 0
27 start = end = time.time()
28
29 # At least a number of iterations, and at least 2 seconds
30 while iterations < 10 or end - start < 2:
31 iterations += 1
32 rsa.newkeys(bitsize, accurate=accurate, poolsize=poolsize)
33 end = time.time()
34
35 duration = end - start
36 dur_per_call = duration / iterations
37
Sybren A. Stüveld3d10342016-01-22 11:36:06 +010038 print('%5i bit: %9.3f sec. (%i iterations over %.1f seconds)' %
39 (bitsize, dur_per_call, iterations, duration))
40
Sybren A. Stüvel360d0422011-08-10 12:52:59 +020041
Sybren A. Stüvelf95dbb72016-01-22 12:19:09 +010042if __name__ == '__main__':
43 for bitsize in (128, 256, 384, 512, 1024, 2048, 3072, 4096):
44 run_speed_test(bitsize)