stringstream.bench.cpp 935 B

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