176TEST_CASE(
"jau_cfmt_benchmark_int_all",
"[benchmark][jau][std::string][format_int]") {
177 const size_t loops = 1000;
178 WARN(
"Benchmark with " + std::to_string(
loops) +
" loops");
181 static constexpr const std::string_view format_check_exp1 =
"format_check: -1, 2, -3, 4, -5, 6, -7, 8, -9, 10";
182 static constexpr const std::string_view format_check_exp2 =
"format_check: -1, 02, -03, 0004, -0005, 000006, -000007, 00000008, -00000009, 0000000010";
198 BENCHMARK(
"fmt1.130 formatR rsrved bench") {
199 volatile size_t res = 0;
200 for(
size_t i = 0; i <
loops; ++i ) {
204 jau::cfmt::formatR(s,
"format_check: %hhd, %hhu, %hd, %hu, %d, %u, %ld, %lu, %zd, %zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
205 REQUIRE(format_check_exp1 == s);
206 res = res + s.size();
210 BENCHMARK(
"fmt1.132 format rsrved bench") {
211 volatile size_t res = 0;
212 for(
size_t i = 0; i <
loops; ++i ) {
213 std::string s =
jau::format_string(
"format_check: %hhd, %hhu, %hd, %hu, %d, %u, %ld, %lu, %zd, %zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
214 REQUIRE(format_check_exp1 == s);
215 res = res + s.size();
219 BENCHMARK(
"fmtX.132 snprintf rsrved bench") {
220 volatile size_t res = 0;
221 for(
size_t i = 0; i <
loops; ++i ) {
226 size_t nchars = std::snprintf(&s[0], bsz,
"format_check: %hhd, %hhu, %hd, %hu, %d, %u, %ld, %lu, %zd, %zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
230 REQUIRE(format_check_exp1 == s);
235 BENCHMARK(
"fmt1.142 format bench") {
236 volatile size_t res = 0;
237 for(
size_t i = 0; i <
loops; ++i ) {
239 std::string s =
jau::cfmt::format(
"format_check: %hhd, %hhu, %hd, %hu, %d, %u, %ld, %lu, %zd, %zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
240 REQUIRE(format_check_exp1 == s);
241 res = res + s.size();
246 BENCHMARK(
"fmtX.150 stringstream bench") {
247 volatile size_t res = 0;
248 for(
size_t i = 0; i <
loops; ++i ) {
249 std::ostringstream ss1;
250 ss1 <<
"format_check: "
252 << unsigned(i2) <<
", "
261 std::string s = ss1.str();
262 REQUIRE(format_check_exp1 == s);
263 res = res + s.size();
271 BENCHMARK(
"fmt1.230 formatR rsrved bench") {
272 volatile size_t res = 0;
273 for(
size_t i = 0; i <
loops; ++i ) {
277 jau::cfmt::formatR(s,
"format_check: %01hhd, %02hhu, %03hd, %04hu, %05d, %06u, %07ld, %08lu, %09zd, %010zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
278 REQUIRE(format_check_exp2 == s);
279 res = res + s.size();
283 BENCHMARK(
"fmt1.232 format rsrved bench") {
284 volatile size_t res = 0;
285 for(
size_t i = 0; i <
loops; ++i ) {
286 std::string s =
jau::format_string(
"format_check: %01hhd, %02hhu, %03hd, %04hu, %05d, %06u, %07ld, %08lu, %09zd, %010zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
287 REQUIRE(format_check_exp2 == s);
288 res = res + s.size();
292 BENCHMARK(
"fmtX.232 snprintf rsrved bench") {
293 volatile size_t res = 0;
294 for(
size_t i = 0; i <
loops; ++i ) {
299 size_t nchars = std::snprintf(&s[0], bsz,
"format_check: %01hhd, %02hhu, %03hd, %04hu, %05d, %06u, %07ld, %08lu, %09zd, %010zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
303 REQUIRE(format_check_exp2 == s);
308 BENCHMARK(
"fmt1.242 format bench") {
309 volatile size_t res = 0;
310 for(
size_t i = 0; i <
loops; ++i ) {
312 std::string s =
jau::cfmt::format(
"format_check: %01hhd, %02hhu, %03hd, %04hu, %05d, %06u, %07ld, %08lu, %09zd, %010zu", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
313 REQUIRE(format_check_exp2 == s);
314 res = res + s.size();