Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

"""This module holds the benchmark tests for DGILibExtra.""" 

 

from pydgilib_extra.dgilib_data import LoggerData 

from pydgilib.dgilib_config import INTERFACE_GPIO 

from pydgilib_extra.dgilib_extra_config import INTERFACE_POWER 

 

num_iterations = 1000 

num_values = 1000 

 

 

def data_iadd_speed(num_iterations=10, num_values=1000): 

"""test_data_iadd_speed.""" 

data = LoggerData([INTERFACE_POWER, INTERFACE_GPIO]) 

for _ in range(num_iterations): 

data += { 

INTERFACE_POWER: (list(range(num_values)), list(range(num_values))), 

INTERFACE_GPIO: (list(range(num_values)), list(range(num_values)))} 

return data 

 

 

def test_data_iadd_speed(benchmark): 

"""Benchmark iadd speed.""" 

result = benchmark(data_iadd_speed, num_iterations, num_values) 

 

assert len(result[INTERFACE_POWER]) == num_iterations * num_values 

assert len(result[INTERFACE_GPIO]) == num_iterations * num_values 

 

 

def data_no_class_speed(num_iterations=10, num_values=1000): 

"""data_no_class_speed.""" 

data = {INTERFACE_POWER: ([], []), INTERFACE_GPIO: ([], [])} 

for _ in range(num_iterations): 

data[INTERFACE_POWER][0].extend(list(range(num_values))) 

data[INTERFACE_POWER][1].extend(list(range(num_values))) 

data[INTERFACE_GPIO][0].extend(list(range(num_values))) 

data[INTERFACE_GPIO][1].extend(list(range(num_values))) 

return data 

 

 

def test_data_no_class_speed(benchmark): 

"""Benchmark no_class speed.""" 

result = benchmark(data_no_class_speed, num_iterations, num_values) 

 

assert len(result[INTERFACE_POWER][0]) == num_iterations * num_values 

assert len(result[INTERFACE_POWER][1]) == num_iterations * num_values 

assert len(result[INTERFACE_GPIO][0]) == num_iterations * num_values 

assert len(result[INTERFACE_GPIO][1]) == num_iterations * num_values