1 /** 2 * Copyright (c) 2016-present, Facebook, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "benchmark/benchmark.h" 18 19 #include <c10/util/Logging.h> 20 21 #if defined(__GNUC__) 22 #define NOINLINE __attribute__((noinline)) 23 #else 24 #define NOINLINE 25 #endif 26 call(int id)27NOINLINE int call(int id) { 28 C10_LOG_API_USAGE_ONCE("bla"); 29 return id%2; 30 } 31 call_no_logging(int id)32NOINLINE int call_no_logging(int id) { 33 return id%2; 34 } 35 BM_APILogging(benchmark::State & state)36static void BM_APILogging(benchmark::State& state) { 37 int id = 0; 38 while (state.KeepRunning()) { 39 for (int i = 0; i < 1000; ++i) { 40 id += 1 + call(id); 41 } 42 } 43 benchmark::DoNotOptimize(id); 44 } 45 BENCHMARK(BM_APILogging); 46 BM_NoAPILogging(benchmark::State & state)47static void BM_NoAPILogging(benchmark::State& state) { 48 int id = 0; 49 while (state.KeepRunning()) { 50 for (int i = 0; i < 1000; ++i) { 51 id += 1 + call_no_logging(id); 52 } 53 } 54 benchmark::DoNotOptimize(id); 55 } 56 BENCHMARK(BM_NoAPILogging); 57 58 BENCHMARK_MAIN(); 59