0

我编写了一个简单的数据库库,并希望在固定的持续时间(比如 10 秒)内对其读/写性能进行基准测试。

从原理上讲,我想让两个线程竞争(一个读取,一个写入),并通过沿以下行进行采样来查看每个线程在给定时间执行的事件数:

void benchmark() {
  init();
  atomic<bool> keepAlive{true};
  atomic<unsigned> reads{0}, writes{0};
  thread([](){
    while (keepAlive) {
      read();
      ++reads;
      sleep(x);
    }
  });
  thread([](){
    while (keepAlive) {
      write();
      ++writes;
      sleep(x);
    }
  });
  while (< 10s) {
    unsigned preSample{reads};
    sleep(1000 / samples_per_s);
    unsigned sampledReads{reads - preSample};
    // write to e.g. csv table
  }
  keepAlive = false;
  // join threads
}

然后,我想使用 pgfplots 绘制收集到的数据点(即在多个图中,每个图中使用经过的时间作为 x,事件计数作为 y)。

我想知道是否有图书馆或首选方式来做这样的事情。我最初考虑使用谷歌基准,但我对此完全陌生,不知道如何生成结果,因此我不会为每个生成的数据点获得一个新列。

4

0 回答 0