File: perf-sanity.cc

package info (click to toggle)
fmtlib 11.1.1%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,772 kB
  • sloc: cpp: 22,591; ansic: 758; python: 504; sh: 53; makefile: 16; javascript: 4
file content (25 lines) | stat: -rw-r--r-- 764 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// A quick and dirty performance test.
// For actual benchmarks see https://github.com/fmtlib/format-benchmark.

#include <atomic>
#include <chrono>
#include <iterator>

#include "fmt/format.h"

int main() {
  const int n = 10000000;

  auto start = std::chrono::steady_clock::now();
  for (int iteration = 0; iteration < n; ++iteration) {
    auto buf = fmt::memory_buffer();
    fmt::format_to(std::back_inserter(buf),
                   "Hello, {}. The answer is {} and {}.", 1, 2345, 6789);
  }
  std::atomic_signal_fence(std::memory_order_acq_rel);  // Clobber memory.
  auto end = std::chrono::steady_clock::now();

  // Print time in milliseconds.
  std::chrono::duration<double> duration = end - start;
  fmt::print("{:.1f}\n", duration.count() * 1000);
}