u3: improve %bout time printing

Now prints micro-, milli-, or full seconds, in the style of
u3a_print_memory (|mass).
This commit is contained in:
fang 2022-04-11 00:43:45 +02:00
parent 7cff021795
commit 3deea4df0e
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
3 changed files with 29 additions and 3 deletions

View File

@ -677,6 +677,11 @@
void
u3a_lop(c3_w lab_w);
/* u3a_print_time: print microsecond time.
*/
void
u3a_print_time(c3_c* str_c, c3_c* cap_c, c3_d mic_d);
/* u3a_print_memory(): print memory amount.
*/
void

View File

@ -1922,6 +1922,27 @@ u3a_discount_noun(u3_noun som)
}
}
/* u3a_print_time: print microsecond time.
*/
void
u3a_print_time(c3_c* str_c, c3_c* cap_c, c3_d mic_d)
{
c3_assert( 0 != str_c );
c3_w sec_w = (mic_d / 1000000);
c3_w mec_w = (mic_d % 1000000) / 1000;
c3_w mic_w = (mic_d % 1000);
if ( sec_w ) {
sprintf(str_c, "%s s/%d.%03d.%03d", cap_c, sec_w, mec_w, mic_w);
}
else if ( mec_w ) {
sprintf(str_c, "%s ms/%d.%03d", cap_c, mec_w, mic_w);
}
else {
sprintf(str_c, "%s \xc2\xb5s/%d", cap_c, mic_w);
}
}
/* u3a_print_memory: print memory amount.
*/

View File

@ -1736,8 +1736,8 @@ _n_hilt_hind(u3_noun tok, u3_noun pro)
u3_noun p_tok, q_tok;
if ( (c3y == u3r_cell(tok, &p_tok, &q_tok)) && (c3__bout == p_tok) ) {
u3_atom delta = u3ka_sub(u3i_chub(u3t_trace_time()), u3k(q_tok));
c3_c str_c[64];
snprintf(str_c, 63, "took %" PRIu64 "\xc2\xb5s", u3r_chub(0, delta) );
c3_c str_c[64];
u3a_print_time(str_c, "took", u3r_chub(0, delta));
u3t_slog(u3nc(0, u3i_string(str_c)));
u3z(delta);
}
@ -1820,7 +1820,7 @@ _n_hint_hind(u3_noun tok, u3_noun pro)
// format the timing report
c3_c str_c[64];
snprintf(str_c, 63, "took %" PRIu64 "\xc2\xb5s", u3r_chub(0, delta) );
u3a_print_time(str_c, "took", u3r_chub(0, delta));
// join the timing report with the original tank from q_q_tok like so:
// "q_q_tok: report"