stringstream.bench.cpp 946 B

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