| 1 |
//---------------------------------------------------------------------- |
| 2 |
// File: perf.cpp |
| 3 |
// Programmer: Sunil Arya and David Mount |
| 4 |
// Description: Methods for performance stats |
| 5 |
// Last modified: 01/27/10 (Version 1.1.2) |
| 6 |
//---------------------------------------------------------------------- |
| 7 |
// Copyright (c) 1997-2010 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 |
// Revision 1.1.2 01/27/10 |
| 28 |
// Fixed minor compilation bugs for new versions of gcc |
| 29 |
//---------------------------------------------------------------------- |
| 30 |
|
| 31 |
#include <ANN/ANN.h> // basic ANN includes |
| 32 |
#include <ANN/ANNperf.h> // performance includes |
| 33 |
|
| 34 |
using namespace std; // make std:: available |
| 35 |
|
| 36 |
//---------------------------------------------------------------------- |
| 37 |
// Performance statistics |
| 38 |
// The following data and routines are used for computing |
| 39 |
// performance statistics for nearest neighbor searching. |
| 40 |
// Because these routines can slow the code down, they can be |
| 41 |
// activated and deactiviated by defining the PERF variable, |
| 42 |
// by compiling with the option: -DPERF |
| 43 |
//---------------------------------------------------------------------- |
| 44 |
|
| 45 |
//---------------------------------------------------------------------- |
| 46 |
// Global counters for performance measurement |
| 47 |
//---------------------------------------------------------------------- |
| 48 |
|
| 49 |
int ann_Ndata_pts = 0; // number of data points |
| 50 |
int ann_Nvisit_lfs = 0; // number of leaf nodes visited |
| 51 |
int ann_Nvisit_spl = 0; // number of splitting nodes visited |
| 52 |
int ann_Nvisit_shr = 0; // number of shrinking nodes visited |
| 53 |
int ann_Nvisit_pts = 0; // visited points for one query |
| 54 |
int ann_Ncoord_hts = 0; // coordinate hits for one query |
| 55 |
int ann_Nfloat_ops = 0; // floating ops for one query |
| 56 |
ANNsampStat ann_visit_lfs; // stats on leaf nodes visits |
| 57 |
ANNsampStat ann_visit_spl; // stats on splitting nodes visits |
| 58 |
ANNsampStat ann_visit_shr; // stats on shrinking nodes visits |
| 59 |
ANNsampStat ann_visit_nds; // stats on total nodes visits |
| 60 |
ANNsampStat ann_visit_pts; // stats on points visited |
| 61 |
ANNsampStat ann_coord_hts; // stats on coordinate hits |
| 62 |
ANNsampStat ann_float_ops; // stats on floating ops |
| 63 |
// |
| 64 |
ANNsampStat ann_average_err; // average error |
| 65 |
ANNsampStat ann_rank_err; // rank error |
| 66 |
|
| 67 |
//---------------------------------------------------------------------- |
| 68 |
// Routines for statistics. |
| 69 |
//---------------------------------------------------------------------- |
| 70 |
|
| 71 |
DLL_API void annResetStats(int data_size) // reset stats for a set of queries |
| 72 |
{ |
| 73 |
ann_Ndata_pts = data_size; |
| 74 |
ann_visit_lfs.reset(); |
| 75 |
ann_visit_spl.reset(); |
| 76 |
ann_visit_shr.reset(); |
| 77 |
ann_visit_nds.reset(); |
| 78 |
ann_visit_pts.reset(); |
| 79 |
ann_coord_hts.reset(); |
| 80 |
ann_float_ops.reset(); |
| 81 |
ann_average_err.reset(); |
| 82 |
ann_rank_err.reset(); |
| 83 |
} |
| 84 |
|
| 85 |
DLL_API void annResetCounts() // reset counts for one query |
| 86 |
{ |
| 87 |
ann_Nvisit_lfs = 0; |
| 88 |
ann_Nvisit_spl = 0; |
| 89 |
ann_Nvisit_shr = 0; |
| 90 |
ann_Nvisit_pts = 0; |
| 91 |
ann_Ncoord_hts = 0; |
| 92 |
ann_Nfloat_ops = 0; |
| 93 |
} |
| 94 |
|
| 95 |
DLL_API void annUpdateStats() // update stats with current counts |
| 96 |
{ |
| 97 |
ann_visit_lfs += ann_Nvisit_lfs; |
| 98 |
ann_visit_nds += ann_Nvisit_spl + ann_Nvisit_lfs; |
| 99 |
ann_visit_spl += ann_Nvisit_spl; |
| 100 |
ann_visit_shr += ann_Nvisit_shr; |
| 101 |
ann_visit_pts += ann_Nvisit_pts; |
| 102 |
ann_coord_hts += ann_Ncoord_hts; |
| 103 |
ann_float_ops += ann_Nfloat_ops; |
| 104 |
} |
| 105 |
|
| 106 |
// print a single statistic |
| 107 |
void print_one_stat(const char* title, ANNsampStat s, double div) |
| 108 |
{ |
| 109 |
cout << title << "= [ "; |
| 110 |
cout.width(9); cout << s.mean()/div << " : "; |
| 111 |
cout.width(9); cout << s.stdDev()/div << " ]<"; |
| 112 |
cout.width(9); cout << s.min()/div << " , "; |
| 113 |
cout.width(9); cout << s.max()/div << " >\n"; |
| 114 |
} |
| 115 |
|
| 116 |
DLL_API void annPrintStats( // print statistics for a run |
| 117 |
ANNbool validate) // true if average errors desired |
| 118 |
{ |
| 119 |
cout.precision(4); // set floating precision |
| 120 |
cout << " (Performance stats: " |
| 121 |
<< " [ mean : stddev ]< min , max >\n"; |
| 122 |
print_one_stat(" leaf_nodes ", ann_visit_lfs, 1); |
| 123 |
print_one_stat(" splitting_nodes ", ann_visit_spl, 1); |
| 124 |
print_one_stat(" shrinking_nodes ", ann_visit_shr, 1); |
| 125 |
print_one_stat(" total_nodes ", ann_visit_nds, 1); |
| 126 |
print_one_stat(" points_visited ", ann_visit_pts, 1); |
| 127 |
print_one_stat(" coord_hits/pt ", ann_coord_hts, ann_Ndata_pts); |
| 128 |
print_one_stat(" floating_ops_(K) ", ann_float_ops, 1000); |
| 129 |
if (validate) { |
| 130 |
print_one_stat(" average_error ", ann_average_err, 1); |
| 131 |
print_one_stat(" rank_error ", ann_rank_err, 1); |
| 132 |
} |
| 133 |
cout.precision(0); // restore the default |
| 134 |
cout << " )\n"; |
| 135 |
cout.flush(); |
| 136 |
} |