0

Basically I want to measure the time while traversing over a packet dump file. Looking at the google benchmark documentation, I have come with:

BENCHMARK_DEFINE_F(MyFixture, FooTest)(benchmark::State& state) {
   for (auto _ : state) {
      // read
      if (readPacket() == NO_MORE_PACKET) {
          break;
      }

      if (!isPacketOfConsideration()) {
          continue;
      }

      // some extra bookkeeping code if required

      time t1{};
      processPacket();
      time t2{};
      state.SetIterationTime(t2 - t1);
  }
}

BENCHMARK_REGISTER_F(MyFixture, Footest)->UseManualTime();

The above is a pseudocode which uses manual time to measure and set iteration time. The questions are basically:

  1. Can I break from the google benchmark's for loop on the state?
  2. Can I continue the google benchmark's for loop on the state without setting iteration time?
themagicalyang
  • 2,493
  • 14
  • 21
  • The whole point of google benchmark is to avoid wasting time by writing your own timer and other measurement function. Basically you should rewrite this code to let the framework run the measured code 1000000 times and calculate execution time for you. – user7860670 Dec 26 '19 at 10:37
  • @user7860670 The input is a packet file, how would that work then? – themagicalyang Dec 26 '19 at 10:40

1 Answers1

1

I would suggest trying black box testing. Micro benchmarks here will likely not help.

I would divide this in several steps.

  1. Generate or record lots of packet data.
  2. Feed this packet data in your parser and measure time needed to fully process it. Potentially this can be function inside your code, or a whole application.
  3. Make change, rerun benchmark, compare results

I worked on open source project, which used this scheme for benchmarking of game server. First, sendto and recv function were hooked and all packets were recorded. Then sleep was hooked, so server didn't sleep between game loop iterations. sendto just returns and recv reads packet data from file.

Detailed description.

Black box testing

Inline
  • 2,566
  • 1
  • 16
  • 32
  • I already do a full run benchmark. And that is the master benchmark I look for. But it is kind of unwieldy to a variety of reasons. It takes longer, needs to run entire on packet, also I run on a production machine. I don't use google benchmark for that, it's a simple measure and print thing. But now I was trying to benchmark smaller units of the code. – themagicalyang Dec 26 '19 at 11:36