1// Copyright 2015 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15#include "counter.h" 16 17namespace benchmark { 18namespace internal { 19 20double Finish(Counter const& c, int64_t iterations, double cpu_time, 21 double num_threads) { 22 double v = c.value; 23 if (c.flags & Counter::kIsRate) { 24 v /= cpu_time; 25 } 26 if (c.flags & Counter::kAvgThreads) { 27 v /= num_threads; 28 } 29 if (c.flags & Counter::kIsIterationInvariant) { 30 v *= iterations; 31 } 32 if (c.flags & Counter::kAvgIterations) { 33 v /= iterations; 34 } 35 return v; 36} 37 38void Finish(UserCounters* l, int64_t iterations, double cpu_time, double num_threads) { 39 for (auto& c : *l) { 40 c.second.value = Finish(c.second, iterations, cpu_time, num_threads); 41 } 42} 43 44void Increment(UserCounters* l, UserCounters const& r) { 45 // add counters present in both or just in *l 46 for (auto& c : *l) { 47 auto it = r.find(c.first); 48 if (it != r.end()) { 49 c.second.value = c.second + it->second; 50 } 51 } 52 // add counters present in r, but not in *l 53 for (auto const& tc : r) { 54 auto it = l->find(tc.first); 55 if (it == l->end()) { 56 (*l)[tc.first] = tc.second; 57 } 58 } 59} 60 61bool SameNames(UserCounters const& l, UserCounters const& r) { 62 if (&l == &r) return true; 63 if (l.size() != r.size()) { 64 return false; 65 } 66 for (auto const& c : l) { 67 if (r.find(c.first) == r.end()) { 68 return false; 69 } 70 } 71 return true; 72} 73 74} // end namespace internal 75} // end namespace benchmark 76