From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/test/old/testcounter.cc | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/test/old/testcounter.cc (limited to 'src/test/old/testcounter.cc') diff --git a/src/test/old/testcounter.cc b/src/test/old/testcounter.cc new file mode 100644 index 00000000..4e40914f --- /dev/null +++ b/src/test/old/testcounter.cc @@ -0,0 +1,73 @@ + +#include "common/DecayCounter.h" + +#include + +#include +using namespace std; + +struct RealCounter { +public: + list hits; + + void hit(int ms) { + hits.push_back(ms); + } + + int get(double hl, int now) { + trim(now-hl); + return hits.size(); + } + + void trim(int to) { + while (!hits.empty() && + hits.front() < to) + hits.pop_front(); + } + + +}; + +int main(int argc, char **argv) +{ + int target; + double hl = atof(argv[1]); + cerr << "halflife " << hl << endl; + + DecayCounter dc(hl); + RealCounter rc; + + DecayCounter::time now = DecayCounter::clock::now(); + + for (int ms=0; ms < 300*1000; ms++) { + if (ms % 30000 == 0) { + target = 1 + (rand() % 10) * 10; + if (ms > 200000) target = 0; + } + + if (target && + (rand() % (1000/target) == 0)) { + dc.hit(); + rc.hit(ms); + } + + if (ms % 500 == 0) dc.get(now); + if (ms % 100 == 0) { + //dc.get(now); + DecayCounter o = dc; + cout << ms << "\t" + << target*hl << "\t" + << rc.get(hl*1000, ms) << "\t" + << o.get(now) << "\t" + << dc.val << "\t" + // << dc.delta << "\t" + << o.get_last_vel() << "\t" + << o.get_last() + o.get_last_vel() << "\t" + << endl; + } + + usleep(1); + now = DecayCounter::clock::now(); + } + +} -- cgit v1.2.3