From 32123d6cb58443d5664d2272287ab24c2cb9db1c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 24 Apr 2019 07:37:10 +1000 Subject: [PATCH] emory-compare: print percentage matched --- emory-compare.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/emory-compare.cpp b/emory-compare.cpp index 3b6893d..b28dc86 100644 --- a/emory-compare.cpp +++ b/emory-compare.cpp @@ -166,11 +166,18 @@ int main (int argc, char const **argv) std::clog << "Finding common\n"; auto const &found = common (target, source); - std::size_t total = 0; + std::size_t matching = 0; for (auto const &i: found) { std::cout << i << '\n'; - total += i.offset.second - i.offset.first; + matching += i.offset.second - i.offset.first; } - std::cout << "Found " << found.size () << " chunks of " << total << " bytes\n"; + std::size_t const total = std::accumulate ( + target.elements.begin (), + target.elements.end (), + 0u, + [] (auto const &a, auto const &b) { return a + b.offset.second - b.offset.first; } + ); + + std::cout << "Found " << found.size () << " chunks of " << matching << " bytes for a factor of " << float (matching) / total << "\n"; }