test_median.cxx
Go to the documentation of this file.
1 #include "WireCellUtil/ExecMon.h"
3 
4 #include <random>
5 #include <iostream>
6 using namespace std;
7 using namespace WireCell::Waveform;
8 
9 int main()
10 {
11  WireCell::ExecMon em ("test median starts");
12  std::random_device rd;
13  std::default_random_engine re(rd());
14  std::uniform_real_distribution<> dist(0, 1000);
15 
16  em("generate randoms");
17 
18  const int nmaxbins = 10000;
19  std::vector<float> data(nmaxbins);
20  for(int ind=0; ind<nmaxbins; ++ind) {
21  data[ind] = dist(re);
22  }
23 
24  const int ntimes = 10000;
25  em("start scaling tests");
26  int sizes[] = {100, 1000, 10000, 0};
27  float dummy = 0; // don't optimize away
28  for (int ind=0; sizes[ind]; ++ind) {
29  auto size = sizes[ind];
30  std::vector<float> chunk(data.begin(), data.begin()+size);
31 
32  em("start median");
33  float med1 = median(chunk);
34  cerr << ind << ": median of " << size << " = " << med1 << endl;
35  for (int tmp=0; tmp<ntimes; ++tmp) {
36  dummy += median(chunk);
37  }
38  cerr << em("end medium (many times)") << endl;
39 
40 
41  em("start median_binned");
42  float med2 = median_binned(chunk);
43  cerr << ind << ": median_binned of " << size << " = " << med2 << endl;
44  for (int tmp=0; tmp<ntimes; ++tmp) {
45  dummy += median_binned(chunk);
46  }
47  cerr << em("end medium_binned (many times)") << endl;
48  cerr << "Median difference: " << med1-med2 << endl;
49 
50  em("done with chunked test");
51  }
52 
53  cerr << em.summary() << endl;
54  return 0;
55 }
int main()
Definition: test_median.cxx:9
STL namespace.
basic_data data
Definition: format.h:764
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
string tmp
Definition: languages.py:63
real_t median_binned(realseq_t &wave)
Definition: Waveform.cxx:81
cet::LibraryManager dummy("noplugin")
std::string summary() const
Return summary up to now.
Definition: ExecMon.cxx:21
double median(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:25
QTextStream & endl(QTextStream &s)