ratioText function

String ratioText(
  1. double score,
  2. double baseline, [
  3. String prefix = '',
  4. String suffix = '',
])

2.5x faster or 2.5x slower for score against baseline, wrapped in prefix and suffix; empty when either is not positive or they are equal to two decimals.

Implementation

String ratioText(
  double score,
  double baseline, [
  String prefix = '',
  String suffix = '',
]) {
  if (score <= 0 || baseline <= 0) return '';
  final faster = score >= baseline;
  final ratio = faster ? score / baseline : baseline / score;
  final text = formatDecimal(ratio);
  if (text == '1') return '';
  return '$prefix${text}x ${faster ? 'faster' : 'slower'}$suffix';
}