mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
enmetric()ize total time output in demo summary
This commit is contained in:
parent
c00fc3c3f7
commit
b37ea582a3
@ -411,15 +411,16 @@ int main(int argc, char** argv){
|
||||
bool failed = false;
|
||||
printf("\n");
|
||||
printf(" total│frames│output(B)│ rendering│%%r│%6s│\n", "FPS");
|
||||
printf("══╤═╤═══════╪══════╪═════════╪══════════╪══╪══════╡\n");
|
||||
printf("══╤═╤════════╪══════╪═════════╪══════════╪══╪══════╡\n");
|
||||
for(size_t i = 0 ; i < strlen(demos) ; ++i){
|
||||
char totalbuf[BPREFIXSTRLEN + 1];
|
||||
char timebuf[PREFIXSTRLEN + 1];
|
||||
qprefix(results[i].timens, GIG, timebuf, 0);
|
||||
bprefix(results[i].stats.render_bytes, 1, totalbuf, 0);
|
||||
double avg = results[i].stats.render_ns / (double)results[i].stats.renders;
|
||||
printf("%2zu│%c│%2lu.%03lus│%6lu│%*s│%8juµs│%2ld│%6.1f│%s\n", i,
|
||||
printf("%2zu│%c│%*ss│%6lu│%*s│%8juµs│%2ld│%6.1f│%s\n", i,
|
||||
results[i].selector,
|
||||
results[i].timens / GIG,
|
||||
(results[i].timens % GIG) / 1000000,
|
||||
PREFIXSTRLEN, timebuf,
|
||||
results[i].stats.renders,
|
||||
BPREFIXSTRLEN, totalbuf,
|
||||
results[i].stats.render_ns / 1000,
|
||||
|
@ -23,7 +23,7 @@ const char *enmetric(uintmax_t val, unsigned decimal, char *buf, int omitdec,
|
||||
|
||||
pthread_once(&ponce, convinit);
|
||||
if(decisep == NULL){
|
||||
|
||||
return NULL;
|
||||
}
|
||||
if(decimal == 0 || mult == 0){
|
||||
return NULL;
|
||||
@ -68,10 +68,13 @@ const char *enmetric(uintmax_t val, unsigned decimal, char *buf, int omitdec,
|
||||
buf[sprintfed + 1] = '\0';
|
||||
}
|
||||
}else{ // unscaled output, consumed == 0, dv == mult
|
||||
// val / decimal < dv (or we ran out of prefixes)
|
||||
if(omitdec && val % decimal == 0){
|
||||
sprintf(buf, "%ju", val / decimal);
|
||||
}else{
|
||||
sprintf(buf, "%ju%s%02ju", val / decimal, decisep, val % decimal);
|
||||
uintmax_t divider = (decimal > mult ? decimal / mult : 1) * 10;
|
||||
uintmax_t remain = (val % decimal) / divider;
|
||||
sprintf(buf, "%ju%s%02ju", val / decimal, decisep, remain);
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
|
@ -321,4 +321,17 @@ TEST_CASE("Enmetric") {
|
||||
CHECK(sizeof(suffixes) * 10 > i);
|
||||
}
|
||||
|
||||
// Output ought be scaled down for output while maintaining precision during
|
||||
// computation of that output. For instance, we might feed a number of
|
||||
// nanoseconds, but want output in seconds.
|
||||
// This requires 'decimal' = 1000000000.
|
||||
SUBCASE("ScaledGig") {
|
||||
char gold[PREFIXSTRLEN + 1] = "9.02";
|
||||
char buf[PREFIXSTRLEN + 1];
|
||||
uintmax_t val = 9027854993;
|
||||
uintmax_t decimal = 1000000000;
|
||||
REQUIRE(qprefix(val, decimal, buf, 0));
|
||||
CHECK(!strcmp(buf, gold));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -74,7 +74,6 @@ TEST_CASE("RenderTest") {
|
||||
free(egc);
|
||||
egc = notcurses_at_yx(nc_, 0, 2, &c);
|
||||
REQUIRE(egc);
|
||||
fprintf(stderr, "HAVE [%s] WANT \xe5\xbd\xa2\n", egc);
|
||||
CHECK(!strcmp("\xe5\xbd\xa2", egc));
|
||||
CHECK(cell_double_wide_p(&c));
|
||||
free(egc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user