Skip to content

Commit cd4f81d

Browse files
time tests
1 parent 9e19fe5 commit cd4f81d

4 files changed

Lines changed: 55 additions & 17 deletions

File tree

‎src/base/base_core.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,15 @@ index_of_zero_u64(U64 *ptr, U64 count)
714714
return max_U64;
715715
}
716716

717+
internal U64
718+
count_digits_u64(U64 v, U64 radix)
719+
{
720+
if (v == 0) { return 1; }
721+
U64 count = 0;
722+
for (U64 x = v; x > 0; x /= radix) { count += 1; }
723+
return count;
724+
}
725+
717726
////////////////////////////////
718727
//~ rjf: Third Party Includes
719728

‎src/base/base_core.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,5 +1069,6 @@ internal U64 u64_array_bsearch(U64 *arr, U64 count, U64 value);
10691069

10701070
internal U64 index_of_zero_u32(U32 *ptr, U64 count);
10711071
internal U64 index_of_zero_u64(U64 *ptr, U64 count);
1072+
internal U64 count_digits_u64(U64 v, U64 radix);
10721073

10731074
#endif // BASE_CORE_H

‎src/torture/torture.c‎

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -516,18 +516,6 @@ t_entry_point(CmdLine *cmdline)
516516
{
517517
radsort(g_torture_tests, g_torture_test_count, t_test_is_before);
518518

519-
U64 max_label_size = 0;
520-
U64 max_group_size = 0;
521-
for EachIndex(i, g_torture_test_count) {
522-
max_label_size = Max(max_label_size, cstring8_length((U8*)g_torture_tests[i].label));
523-
max_group_size = Max(max_group_size, cstring8_length((U8*)g_torture_tests[i].group));
524-
}
525-
526-
U64 dots_min = 10;
527-
U64 dots_size = max_label_size+dots_min;
528-
U8 *dots = push_array(scratch.arena, U8, dots_size);
529-
MemorySet(dots, '.', dots_size);
530-
531519
U64 target_indices_count;
532520
U64 *target_indices;
533521
if (target.node_count == 0) {
@@ -553,16 +541,33 @@ t_entry_point(CmdLine *cmdline)
553541
}
554542
}
555543

544+
U64 max_label_size = 0;
545+
U64 max_group_size = 0;
546+
for EachIndex(i, target_indices_count) {
547+
U64 test_idx = target_indices[i];
548+
max_label_size = Max(max_label_size, cstring8_length((U8*)g_torture_tests[test_idx].label));
549+
max_group_size = Max(max_group_size, cstring8_length((U8*)g_torture_tests[test_idx].group));
550+
}
551+
552+
U64 dots_min = 15;
553+
U64 dots_size = max_label_size+dots_min;
554+
U8 *dots = push_array(scratch.arena, U8, dots_size);
555+
MemorySet(dots, '.', dots_size);
556+
556557
U64 pass_count = 0;
557558
U64 fail_count = 0;
558559
U64 crash_count = 0;
560+
U64 max_digit_count = count_digits_u64(target_indices_count, 10);
561+
U64 total_time_start = os_now_microseconds();
559562
for EachIndex(i, target_indices_count) {
560563
U64 target_idx = target_indices[i];
561564

562565
// print run progress
563566
U64 dots_count = (max_label_size - cstring8_length((U8*)g_torture_tests[target_idx].label)) + dots_min;
564567
char *spaces = " ";
565-
fprintf(stdout, "[%2I64u/%2I64u] ", i+1, target_indices_count);
568+
U64 curr_digit_count = count_digits_u64(i+1, 10);
569+
int idx_align_space_count = (int)(max_digit_count - curr_digit_count);
570+
fprintf(stdout, "[%.*s%I64u/%I64u] ", idx_align_space_count, spaces, i+1, target_indices_count);
566571
fprintf(stdout, "(%s) %.*s%s", g_torture_tests[target_idx].group, (int)(max_group_size - cstring8_length((U8*)g_torture_tests[target_idx].group)), spaces, g_torture_tests[target_idx].label);
567572
fprintf(stdout, "%.*s", (int)dots_count, dots);
568573

@@ -582,20 +587,30 @@ t_entry_point(CmdLine *cmdline)
582587
}
583588

584589
// run test
590+
U64 run_start_time = os_now_microseconds();
585591
T_RunResult result = t_run(g_torture_tests[target_idx].r);
592+
U64 run_end_time = os_now_microseconds();
586593

587594
// print result
588595
if (result.status == T_RunStatus_Pass) {
589-
fprintf(stdout, "\x1b[32m" "%s" "\x1b[0m" "\n", t_string_from_result(result.status));
596+
fprintf(stdout, "\x1b[32m" "%s" "\x1b[0m", t_string_from_result(result.status));
590597
pass_count += 1;
591598
} else if (result.status == T_RunStatus_Fail) {
592-
fprintf(stdout, "\x1b[31m" "%s" "\x1b[0m" "\n", t_string_from_result(result.status));
599+
fprintf(stdout, "\x1b[31m" "%s" "\x1b[0m", t_string_from_result(result.status));
593600
fail_count += 1;
594601
} else if (result.status == T_RunStatus_Crash) {
595-
fprintf(stdout, "\x1b[33m" "%s" "\x1b[0m" "\n", t_string_from_result(result.status));
602+
fprintf(stdout, "\x1b[33m" "%s" "\x1b[0m", t_string_from_result(result.status));
596603
crash_count += 1;
597604
}
598605

606+
if (result.status == T_RunStatus_Pass) {
607+
U64 d = run_end_time - run_start_time;
608+
DateTime t = date_time_from_micro_seconds(d);
609+
String8 s = string_from_elapsed_time(scratch.arena, t);
610+
fprintf(stdout, " | %.*s", str8_varg(s));
611+
}
612+
fprintf(stdout, "\n");
613+
599614
if (result.status == T_RunStatus_Fail) {
600615
fprintf(stdout, " ERROR: %s:%d: condition: \"%s\"\n", result.fail_file, result.fail_line, result.fail_cond);
601616
}
@@ -604,8 +619,11 @@ t_entry_point(CmdLine *cmdline)
604619
if (g_stop_on_first_fail_or_crash) { goto exit; }
605620
}
606621
}
622+
U64 total_time_end = os_now_microseconds();
607623

608-
fprintf(stdout, "*** Passed: %I64u, Failed: %I64u, Crashed: %I64u ***\n", pass_count, fail_count, crash_count);
624+
U64 total_time_dt = total_time_end - total_time_start;
625+
String8 total_time_str = string_from_elapsed_time(scratch.arena, date_time_from_micro_seconds(total_time_dt));
626+
fprintf(stdout, "*** Passed: %I64u, Failed: %I64u, Crashed: %I64u, Time: %.*s***\n", pass_count, fail_count, crash_count, str8_varg(total_time_str));
609627

610628
exit:;
611629
if (fail_count + crash_count != 0) {

‎src/torture/torture_base.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,14 @@ TEST(bit_array)
9494
}
9595
}
9696

97+
TEST(count_digits)
98+
{
99+
T_Ok(count_digits_u64(0, 10) == 1);
100+
T_Ok(count_digits_u64(99, 10) == 2);
101+
T_Ok(count_digits_u64(999, 10) == 3);
102+
T_Ok(count_digits_u64(9999, 10) == 4);
103+
T_Ok(count_digits_u64(99999, 10) == 5);
104+
T_Ok(count_digits_u64(999999, 10) == 6);
105+
}
106+
97107
#undef T_Group

0 commit comments

Comments
 (0)