Skip to content

Commit 2c4412e

Browse files
author
Rik
committed
performance: Redo determination of sparse array pct precision.
* ov-base-sparse.cc (print_raw): Redo logic for calculating precision of printing percentage to put most common scenario (pct <= 99) first and thus skip rest of code.
1 parent 9eb3f32 commit 2c4412e

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

libinterp/octave-value/ov-base-sparse.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,22 +327,19 @@ octave_base_sparse<T>::print_raw (std::ostream& os,
327327
{
328328
double pct = (nz / dnel * 100);
329329

330-
int prec = 2;
331-
332-
// Display at least 2 significant figures and up to 4 as we
333-
// approach 100%. Avoid having limited precision of the display
334-
// result in reporting 100% for matrices that are not actually
335-
// 100% full.
336-
337-
if (pct == 100)
330+
// Display at least 2 significant digits, and up to 4 as we approach
331+
// 100%. Avoid having limited precision of the display result in
332+
// reporting 100% for matrices that are not actually 100% full.
333+
int prec;
334+
335+
if (pct <= 99)
336+
prec = 2;
337+
else if (pct <= 99.9 || pct == 100)
338338
prec = 3;
339339
else
340340
{
341-
if (pct > 99.9)
342-
prec = 4;
343-
else if (pct > 99)
344-
prec = 3;
345-
341+
// pct is in range (99.9, 100).
342+
prec = 4;
346343
if (pct > 99.99)
347344
pct = 99.99;
348345
}

0 commit comments

Comments
 (0)