All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
measure.h
Go to the documentation of this file.
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File: measure.h (Formerly measure.h)
5  * Description: Statistics for a group of single measurements
6  * Author: Mark Seaman, SW Productivity
7  * Created: Fri Oct 16 14:37:00 1987
8  * Modified: Mon Apr 8 09:42:28 1991 (Mark Seaman) marks@hpgrlt
9  * Language: C
10  * Package: N/A
11  * Status: Reusable Software Component
12  *
13  * (c) Copyright 1987, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  ********************************************************************************
25  */
26 
27 #ifndef MEASURE_H
28 #define MEASURE_H
29 
30 /*
31 ----------------------------------------------------------------------
32  I n c l u d e s
33 ----------------------------------------------------------------------
34 */
35 
36 #include <math.h>
37 
38 /*
39 ----------------------------------------------------------------------
40  T y p e s
41 ----------------------------------------------------------------------
42 */
43 
44 typedef struct
45 {
49 } MEASUREMENT;
50 
51 /*
52 ----------------------------------------------------------------------
53  M a c r o s
54 ----------------------------------------------------------------------
55 */
56 
57 /**********************************************************************
58  * add_sample
59  *
60  * Add one more sample to a measurement.
61  **********************************************************************/
62 
63 #define ADD_SAMPLE(m,s) \
64 (m.sum_of_samples += (float) (s), \
65  m.sum_of_squares += (float) (s) * (float) (s), \
66  ++m.num_samples)
67 
68 /**********************************************************************
69  * mean
70  *
71  * Return the mean value of the measurement.
72  **********************************************************************/
73 
74 #define MEAN(m) \
75 ((m).num_samples ? \
76  ((float) ((m).sum_of_samples / (m).num_samples)) : \
77  0)
78 
79 /**********************************************************************
80  * new_measurement
81  *
82  * Initalize a record to hold a measurement of a group of individual
83  * samples.
84  **********************************************************************/
85 
86 #define new_measurement(m) \
87 ((m).num_samples = 0, \
88  (m).sum_of_samples = 0, \
89  (m).sum_of_squares = 0)
90 
91 /**********************************************************************
92  * number_of_samples
93  *
94  * Return the number of samples in a measurement.
95  **********************************************************************/
96 
97 #define number_of_samples(m) \
98 ((m).num_samples)
99 
100 /**********************************************************************
101  * standard_deviation
102  *
103  * Return the standard deviation of the measurement.
104  **********************************************************************/
105 
106 #define standard_deviation(m) \
107 ((float) sqrt (VARIANCE (m)))
108 
109 /**********************************************************************
110  * variance
111  *
112  * Return the variance of the measurement.
113  **********************************************************************/
114 
115 #define VARIANCE(m) \
116 (((m).num_samples > 1) ? \
117  ((float) \
118  (((m).num_samples * (m).sum_of_squares - \
119  (m).sum_of_samples * (m).sum_of_samples) / \
120  (((m).num_samples - 1) * (m).num_samples))) : \
121  0)
122 
123 /**********************************************************************
124  * print_summary
125  *
126  * Summarize a MEASUREMENT record.
127  **********************************************************************/
128 
129 #define print_summary(string,measure) \
130 cprintf ("\t%-20s \tn = %d, \tm = %4.2f, \ts = %4.2f\n ", \
131  string, \
132  number_of_samples (measure), \
133  MEAN (measure), \
134  standard_deviation (measure))
135 #endif
long num_samples
Definition: measure.h:46
float sum_of_samples
Definition: measure.h:47
float sum_of_squares
Definition: measure.h:48