1
- import math
2
1
import json
2
+ import math
3
+
3
4
import pycurl
4
5
5
6
from py3resttest .constants import DEFAULT_TIMEOUT
6
- from py3resttest .tests import Test , coerce_to_string
7
7
from py3resttest .parsing import *
8
-
9
-
8
+ from py3resttest .testcase import Test , coerce_to_string
10
9
11
10
"""
12
11
Encapsulates logic related to benchmarking
15
14
- Templating/Caching logic specific to benchmarks
16
15
"""
17
16
18
-
19
17
# Curl metrics for benchmarking, key is name in config file, value is pycurl variable
20
18
# Taken from pycurl docs, this is libcurl variable minus the CURLINFO prefix
21
19
# Descriptions of the timing variables are taken from libcurl docs:
51
49
# Total time of the previous request.
52
50
'total_time' : pycurl .TOTAL_TIME ,
53
51
54
-
55
52
# Transfer sizes and speeds
56
53
'size_download' : pycurl .SIZE_DOWNLOAD ,
57
54
'size_upload' : pycurl .SIZE_UPLOAD ,
68
65
# aggregation on an array
69
66
AGGREGATES = {
70
67
'mean_arithmetic' : # AKA the average, good for many things
71
- lambda x : float (sum (x )) / float (len (x )),
68
+ lambda x : float (sum (x )) / float (len (x )),
72
69
'mean' : # Alias for arithmetic mean
73
- lambda x : float (sum (x )) / float (len (x )),
70
+ lambda x : float (sum (x )) / float (len (x )),
74
71
'mean_harmonic' : # Harmonic mean, better predicts average of rates: http://en.wikipedia.org/wiki/Harmonic_mean
75
- lambda x : 1.0 / (sum ([1.0 / float (y ) for y in x ]) / float (len (x ))),
72
+ lambda x : 1.0 / (sum ([1.0 / float (y ) for y in x ]) / float (len (x ))),
76
73
'median' : lambda x : median (x ),
77
74
'std_deviation' : lambda x : std_deviation (x ),
78
75
'sum' : lambda x : sum (x ),
@@ -99,7 +96,7 @@ def std_deviation(array):
99
96
return 0
100
97
101
98
average = AGGREGATES ['mean_arithmetic' ](array )
102
- variance = map (lambda x : (x - average )** 2 , array )
99
+ variance = map (lambda x : (x - average ) ** 2 , array )
103
100
variance = list (variance )
104
101
stdev = AGGREGATES ['mean_arithmetic' ](variance )
105
102
return math .sqrt (stdev )
@@ -234,7 +231,7 @@ def parse_benchmark(base_url, node):
234
231
"Invalid aggregate input: non-string aggregate name" )
235
232
# TODO unicode-safe this
236
233
benchmark .add_metric (coerce_to_string (metricname ),
237
- coerce_to_string (aggregate ))
234
+ coerce_to_string (aggregate ))
238
235
239
236
elif isinstance (metric , str ):
240
237
benchmark .add_metric (coerce_to_string (metric ))
@@ -248,7 +245,7 @@ def parse_benchmark(base_url, node):
248
245
raise TypeError (
249
246
"Invalid aggregate input: non-string aggregate name" )
250
247
benchmark .add_metric (coerce_to_string (metricname ),
251
- coerce_to_string (aggregate ))
248
+ coerce_to_string (aggregate ))
252
249
else :
253
250
raise TypeError (
254
251
"Invalid benchmark metric datatype: " + str (value ))
0 commit comments