@Promezio/

PythonPerformanceMeasurement

Python

No description

fork
loading
Files
  • main.py
  • speedtest.py
main.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
#
#  :#/ promezio
#  www.promezio.it
#  Python: performance measurement
#  Check list vs set performance with timeit and cProfile
#

# Importing external modules
from timeit import timeit
import cProfile

# Importing speed test function from speedtest.py
from speedtest import iterableSpeedTest


# Main program
if __name__ == "__main__": 
  # Check performance with timeit
  print("TIMEIT PERFORMANCE MEASUREMENT . . .")

  timeit_speed_set = timeit("iterableSpeedTest(iterable)", setup="from speedtest import iterableSpeedTest; iterable = set(range(1000))", number=1000)
  timeit_speed_list = timeit("iterableSpeedTest(iterable)", setup="from speedtest import iterableSpeedTest; iterable = list(range(1000))", number=1000)

  # Print timeit performance measurement
  print("Set speed: %i", timeit_speed_set)
  print("List speed: %i", timeit_speed_list)

  #Check performance with cProfile
  print("C-PROFILE PERFORMANCE MEASUREMENT . . .")
  cprofile_speed_set = cProfile.runctx('iterableSpeedTest(set)', {'iterableSpeedTest': iterableSpeedTest,'set': set(range(1000))}, {})
  cprofile_speed_list = cProfile.runctx('iterableSpeedTest(list)', {'iterableSpeedTest': iterableSpeedTest,'list': list(range(1000))}, {})