Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
bench_user.cpp File Reference
#include "user.hpp"
#include <benchmark/benchmark.h>
#include <iostream>
#include <sstream>

Go to the source code of this file.

Functions

static void BM_UserConstructor (const benchmark::State &state)
 
 BENCHMARK (BM_UserConstructor)
 
static void BM_UserPrint (const benchmark::State &state)
 
 BENCHMARK (BM_UserPrint)
 
 BENCHMARK_MAIN ()
 

Function Documentation

◆ BENCHMARK() [1/2]

BENCHMARK ( BM_UserConstructor )

◆ BENCHMARK() [2/2]

BENCHMARK ( BM_UserPrint )

◆ BENCHMARK_MAIN()

BENCHMARK_MAIN ( )

◆ BM_UserConstructor()

static void BM_UserConstructor ( const benchmark::State & state)
static

Definition at line 8 of file c++/benchmarks/bench_user.cpp.

8 {
9 for (auto _ : state) {
10 // Prevent compiler from optimizing away the object
11 benchmark::DoNotOptimize(
12 User("octocat", "The Octocat", "GitHub", "San Francisco"));
13 }
14}
#define _(String)
Definition gi18n-lib.h:32
Structure representing a GitHub user.
Definition user.h:9

References _.

◆ BM_UserPrint()

static void BM_UserPrint ( const benchmark::State & state)
static

Definition at line 18 of file c++/benchmarks/bench_user.cpp.

18 {
19 User user("octocat", "The Octocat", "GitHub", "San Francisco");
20
21 for (auto _ : state) {
22 std::ostringstream oss;
23 std::streambuf *old = std::cout.rdbuf(oss.rdbuf()); // Redirect std::cout
24 user.print();
25 std::cout.rdbuf(old); // Restore original buffer
26
27 benchmark::DoNotOptimize(oss.str()); // Prevent optimization
28 }
29}

References _.