root / rgbdslam / gicp / ann_1.1.1 / src / perf.cpp @ 9240aaa3
History | View | Annotate | Download (5.15 KB)
1 | 9240aaa3 | Alex | //----------------------------------------------------------------------
|
---|---|---|---|
2 | // File: perf.cpp
|
||
3 | // Programmer: Sunil Arya and David Mount
|
||
4 | // Description: Methods for performance stats
|
||
5 | // Last modified: 01/04/05 (Version 1.0)
|
||
6 | //----------------------------------------------------------------------
|
||
7 | // Copyright (c) 1997-2005 University of Maryland and Sunil Arya and
|
||
8 | // David Mount. All Rights Reserved.
|
||
9 | //
|
||
10 | // This software and related documentation is part of the Approximate
|
||
11 | // Nearest Neighbor Library (ANN). This software is provided under
|
||
12 | // the provisions of the Lesser GNU Public License (LGPL). See the
|
||
13 | // file ../ReadMe.txt for further information.
|
||
14 | //
|
||
15 | // The University of Maryland (U.M.) and the authors make no
|
||
16 | // representations about the suitability or fitness of this software for
|
||
17 | // any purpose. It is provided "as is" without express or implied
|
||
18 | // warranty.
|
||
19 | //----------------------------------------------------------------------
|
||
20 | // History:
|
||
21 | // Revision 0.1 03/04/98
|
||
22 | // Initial release
|
||
23 | // Revision 1.0 04/01/05
|
||
24 | // Changed names to avoid namespace conflicts.
|
||
25 | // Added flush after printing performance stats to fix bug
|
||
26 | // in Microsoft Windows version.
|
||
27 | //----------------------------------------------------------------------
|
||
28 | |||
29 | #include <ANN/ANN.h> // basic ANN includes |
||
30 | #include <ANN/ANNperf.h> // performance includes |
||
31 | |||
32 | using namespace std; // make std:: available |
||
33 | |||
34 | //----------------------------------------------------------------------
|
||
35 | // Performance statistics
|
||
36 | // The following data and routines are used for computing
|
||
37 | // performance statistics for nearest neighbor searching.
|
||
38 | // Because these routines can slow the code down, they can be
|
||
39 | // activated and deactiviated by defining the PERF variable,
|
||
40 | // by compiling with the option: -DPERF
|
||
41 | //----------------------------------------------------------------------
|
||
42 | |||
43 | //----------------------------------------------------------------------
|
||
44 | // Global counters for performance measurement
|
||
45 | //----------------------------------------------------------------------
|
||
46 | |||
47 | int ann_Ndata_pts = 0; // number of data points |
||
48 | int ann_Nvisit_lfs = 0; // number of leaf nodes visited |
||
49 | int ann_Nvisit_spl = 0; // number of splitting nodes visited |
||
50 | int ann_Nvisit_shr = 0; // number of shrinking nodes visited |
||
51 | int ann_Nvisit_pts = 0; // visited points for one query |
||
52 | int ann_Ncoord_hts = 0; // coordinate hits for one query |
||
53 | int ann_Nfloat_ops = 0; // floating ops for one query |
||
54 | ANNsampStat ann_visit_lfs; // stats on leaf nodes visits
|
||
55 | ANNsampStat ann_visit_spl; // stats on splitting nodes visits
|
||
56 | ANNsampStat ann_visit_shr; // stats on shrinking nodes visits
|
||
57 | ANNsampStat ann_visit_nds; // stats on total nodes visits
|
||
58 | ANNsampStat ann_visit_pts; // stats on points visited
|
||
59 | ANNsampStat ann_coord_hts; // stats on coordinate hits
|
||
60 | ANNsampStat ann_float_ops; // stats on floating ops
|
||
61 | //
|
||
62 | ANNsampStat ann_average_err; // average error
|
||
63 | ANNsampStat ann_rank_err; // rank error
|
||
64 | |||
65 | //----------------------------------------------------------------------
|
||
66 | // Routines for statistics.
|
||
67 | //----------------------------------------------------------------------
|
||
68 | |||
69 | DLL_API void annResetStats(int data_size) // reset stats for a set of queries |
||
70 | { |
||
71 | ann_Ndata_pts = data_size; |
||
72 | ann_visit_lfs.reset(); |
||
73 | ann_visit_spl.reset(); |
||
74 | ann_visit_shr.reset(); |
||
75 | ann_visit_nds.reset(); |
||
76 | ann_visit_pts.reset(); |
||
77 | ann_coord_hts.reset(); |
||
78 | ann_float_ops.reset(); |
||
79 | ann_average_err.reset(); |
||
80 | ann_rank_err.reset(); |
||
81 | } |
||
82 | |||
83 | DLL_API void annResetCounts() // reset counts for one query |
||
84 | { |
||
85 | ann_Nvisit_lfs = 0;
|
||
86 | ann_Nvisit_spl = 0;
|
||
87 | ann_Nvisit_shr = 0;
|
||
88 | ann_Nvisit_pts = 0;
|
||
89 | ann_Ncoord_hts = 0;
|
||
90 | ann_Nfloat_ops = 0;
|
||
91 | } |
||
92 | |||
93 | DLL_API void annUpdateStats() // update stats with current counts |
||
94 | { |
||
95 | ann_visit_lfs += ann_Nvisit_lfs; |
||
96 | ann_visit_nds += ann_Nvisit_spl + ann_Nvisit_lfs; |
||
97 | ann_visit_spl += ann_Nvisit_spl; |
||
98 | ann_visit_shr += ann_Nvisit_shr; |
||
99 | ann_visit_pts += ann_Nvisit_pts; |
||
100 | ann_coord_hts += ann_Ncoord_hts; |
||
101 | ann_float_ops += ann_Nfloat_ops; |
||
102 | } |
||
103 | |||
104 | // print a single statistic
|
||
105 | void print_one_stat(char *title, ANNsampStat s, double div) |
||
106 | { |
||
107 | cout << title << "= [ ";
|
||
108 | cout.width(9); cout << s.mean()/div << " : "; |
||
109 | cout.width(9); cout << s.stdDev()/div << " ]<"; |
||
110 | cout.width(9); cout << s.min()/div << " , "; |
||
111 | cout.width(9); cout << s.max()/div << " >\n"; |
||
112 | } |
||
113 | |||
114 | DLL_API void annPrintStats( // print statistics for a run |
||
115 | ANNbool validate) // true if average errors desired
|
||
116 | { |
||
117 | cout.precision(4); // set floating precision |
||
118 | cout << " (Performance stats: "
|
||
119 | << " [ mean : stddev ]< min , max >\n";
|
||
120 | print_one_stat(" leaf_nodes ", ann_visit_lfs, 1); |
||
121 | print_one_stat(" splitting_nodes ", ann_visit_spl, 1); |
||
122 | print_one_stat(" shrinking_nodes ", ann_visit_shr, 1); |
||
123 | print_one_stat(" total_nodes ", ann_visit_nds, 1); |
||
124 | print_one_stat(" points_visited ", ann_visit_pts, 1); |
||
125 | print_one_stat(" coord_hits/pt ", ann_coord_hts, ann_Ndata_pts);
|
||
126 | print_one_stat(" floating_ops_(K) ", ann_float_ops, 1000); |
||
127 | if (validate) {
|
||
128 | print_one_stat(" average_error ", ann_average_err, 1); |
||
129 | print_one_stat(" rank_error ", ann_rank_err, 1); |
||
130 | } |
||
131 | cout.precision(0); // restore the default |
||
132 | cout << " )\n";
|
||
133 | cout.flush(); |
||
134 | } |