1 #include "benchmark/benchmark.h" 2 3 #include <sstream> 4 double __attribute__((noinline)) istream_numbers(); 5 6 double istream_numbers() { 7 const char *a[] = { 8 "-6 69 -71 2.4882e-02 -100 101 -2.00005 5000000 -50000000", 9 "-25 71 7 -9.3262e+01 -100 101 -2.00005 5000000 -50000000", 10 "-14 53 46 -6.7026e-02 -100 101 -2.00005 5000000 -50000000" 11 }; 12 13 int a1, a2, a3, a4, a5, a6, a7; 14 double f1 = 0.0, f2 = 0.0, q = 0.0; 15 for (int i=0; i < 3; i++) { 16 std::istringstream s(a[i]); 17 s >> a1 18 >> a2 19 >> a3 20 >> f1 21 >> a4 22 >> a5 23 >> f2 24 >> a6 25 >> a7; 26 q += (a1 + a2 + a3 + a4 + a5 + a6 + a7 + f1 + f2)/1000000; 27 } 28 return q; 29 } 30 31 static void BM_Istream_numbers(benchmark::State &state) { 32 double i = 0; 33 while (state.KeepRunning()) 34 benchmark::DoNotOptimize(i += istream_numbers()); 35 } 36 37 BENCHMARK(BM_Istream_numbers)->RangeMultiplier(2)->Range(1024, 4096); 38 BENCHMARK_MAIN(); 39