-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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(); | ||
|
||
std::chrono::duration<double> duration = end - start; | ||
double total_time = duration.count() * 1000; // Convert to milliseconds. | ||
fmt::print("Total time for formatting {} strings: {:.1f} ms.\n", n, | ||
total_time); | ||
} |