177TEST_CASE(
"jau_cfmt_benchmark_int_all",
"[benchmark][jau][std::string][format_int]") {
178 const size_t loops = 1000;
179 WARN(
"Benchmark with " + std::to_string(
loops) +
" loops");
182 static constexpr const std::string_view format_check_exp1 =
"format_check: -1, 2, -3, 4, -5, 6, -7, 8, -9, 10";
183 static constexpr const std::string_view format_check_exp2 =
"format_check: -1, 02, -03, 0004, -0005, 000006, -000007, 00000008, -00000009, 0000000010";
199 BENCHMARK(
"fmt1.130 formatR rsrved bench") {
200 volatile size_t res = 0;
201 for(
size_t i = 0; i <
loops; ++i ) {
205 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);
206 REQUIRE(format_check_exp1 == s);
207 res = res + s.size();
211 BENCHMARK(
"fmt1.132 format rsrved bench") {
212 volatile size_t res = 0;
213 for(
size_t i = 0; i <
loops; ++i ) {
214 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);
215 REQUIRE(format_check_exp1 == s);
216 res = res + s.size();
220 BENCHMARK(
"fmtX.132 snprintf rsrved bench") {
221 volatile size_t res = 0;
222 for(
size_t i = 0; i <
loops; ++i ) {
227 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);
231 REQUIRE(format_check_exp1 == s);
236 BENCHMARK(
"fmt1.142 format bench") {
237 volatile size_t res = 0;
238 for(
size_t i = 0; i <
loops; ++i ) {
240 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);
241 REQUIRE(format_check_exp1 == s);
242 res = res + s.size();
247 BENCHMARK(
"fmtX.150 stringstream bench") {
248 volatile size_t res = 0;
249 for(
size_t i = 0; i <
loops; ++i ) {
250 std::ostringstream ss1;
251 ss1 <<
"format_check: "
253 << unsigned(i2) <<
", "
262 std::string s = ss1.str();
263 REQUIRE(format_check_exp1 == s);
264 res = res + s.size();
272 BENCHMARK(
"fmt1.230 formatR rsrved bench") {
273 volatile size_t res = 0;
274 for(
size_t i = 0; i <
loops; ++i ) {
278 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);
279 REQUIRE(format_check_exp2 == s);
280 res = res + s.size();
284 BENCHMARK(
"fmt1.232 format rsrved bench") {
285 volatile size_t res = 0;
286 for(
size_t i = 0; i <
loops; ++i ) {
287 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);
288 REQUIRE(format_check_exp2 == s);
289 res = res + s.size();
293 BENCHMARK(
"fmtX.232 snprintf rsrved bench") {
294 volatile size_t res = 0;
295 for(
size_t i = 0; i <
loops; ++i ) {
300 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);
304 REQUIRE(format_check_exp2 == s);
309 BENCHMARK(
"fmt1.242 format bench") {
310 volatile size_t res = 0;
311 for(
size_t i = 0; i <
loops; ++i ) {
313 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);
314 REQUIRE(format_check_exp2 == s);
315 res = res + s.size();
320 BENCHMARK(
"fmtX.250 stringstream bench") {
321 volatile size_t res = 0;
322 for(
size_t i = 0; i <
loops; ++i ) {
323 std::ostringstream ss1;
324 ss1 <<
"format_check: "
326 <<
"-" << std::setw(0) << int(
jau::abs(i1)) <<
", "
327 << std::setw(2) << unsigned(i2) <<
", "
328 <<
"-" << std::setw(3-1) <<
jau::abs(i3) <<
", "
329 << std::setw(4) << i4 <<
", "
330 <<
"-" << std::setw(5-1) <<
jau::abs(i5) <<
", "
331 << std::setw(6) << i6 <<
", "
332 <<
"-" << std::setw(7-1) <<
jau::abs(i7) <<
", "
333 << std::setw(8) << i8 <<
", "
334 <<
"-" << std::setw(9-1) <<
jau::abs(i9) <<
", "
335 << std::setw(10) << i10;
336 std::string s = ss1.str();
337 REQUIRE(format_check_exp2 == s);
338 res = res + s.size();