Ejemplo n.º 1
0
 def to_latex(self, name_parts):
     if not self.cputime_values or not self.walltime_values:
         return ""
     cputime_stats = StatValue.from_list(self.cputime_values)
     walltime_stats = StatValue.from_list(self.walltime_values)
     assert len(name_parts) <= 4
     name_parts += [""] * (4 - len(name_parts))  # ensure length 4
     name = r"}{".join(map(format_command_part, name_parts))
     return "\n".join(
         itertools.chain.from_iterable([[
             r"\StoreBenchExecResult{%s}{Count}{}{%s}%%" %
             (name, self.count)
         ]] + [[
             r"\StoreBenchExecResult{%s}{%s}{}{%s}%%" %
             (name, time_name, util.print_decimal(time_stats.sum)),
             r"\StoreBenchExecResult{%s}{%s}{Avg}{%s}%%" %
             (name, time_name, util.print_decimal(time_stats.avg)),
             r"\StoreBenchExecResult{%s}{%s}{Median}{%s}%%" %
             (name, time_name, util.print_decimal(time_stats.median)),
             r"\StoreBenchExecResult{%s}{%s}{Min}{%s}%%" %
             (name, time_name, util.print_decimal(time_stats.min)),
             r"\StoreBenchExecResult{%s}{%s}{Max}{%s}%%" %
             (name, time_name, util.print_decimal(time_stats.max)),
             r"\StoreBenchExecResult{%s}{%s}{Stdev}{%s}%%" %
             (name, time_name, util.print_decimal(time_stats.stdev)),
         ] for (time_name, time_stats) in [
             ("Cputime", cputime_stats),
             ("Walltime", walltime_stats),
         ]]))
Ejemplo n.º 2
0
 def test_single_value(self):
     v = Decimal("1.23")
     s = StatValue.from_list([v])
     self.assertEqual(s.sum, v)
     self.assertEqual(s.avg, v)
     self.assertEqual(s.max, v)
     self.assertEqual(s.min, v)
     self.assertEqual(s.median, v)
     self.assertEqual(s.stdev, Decimal(0))
    def test_nan(self):
        nan = Decimal("nan")
        v = Decimal("0.123")

        s = StatValue.from_list([nan])
        self.assertTrue(s.sum.is_nan(), "Not NaN, but " + str(s.sum))
        self.assertTrue(s.avg.is_nan(), "Not NaN, but " + str(s.avg))
        self.assertTrue(s.max.is_nan(), "Not NaN, but " + str(s.max))
        self.assertTrue(s.min.is_nan(), "Not NaN, but " + str(s.min))
        self.assertTrue(s.median.is_nan(), "Not NaN, but " + str(s.median))
        self.assertTrue(s.stdev.is_nan(), "Not NaN, but " + str(s.stdev))

        s = StatValue.from_list([nan, v])
        self.assertTrue(s.sum.is_nan(), "Not NaN, but " + str(s.sum))
        self.assertTrue(s.avg.is_nan(), "Not NaN, but " + str(s.avg))
        self.assertTrue(s.max.is_nan(), "Not NaN, but " + str(s.max))
        self.assertTrue(s.min.is_nan(), "Not NaN, but " + str(s.min))
        self.assertTrue(s.median.is_nan(), "Not NaN, but " + str(s.median))
        self.assertTrue(s.stdev.is_nan(), "Not NaN, but " + str(s.stdev))
Ejemplo n.º 4
0
    def test_nan(self):
        nan = Decimal("nan")
        v = Decimal("0.123")

        s = StatValue.from_list([nan])
        self.assertTrue(s.sum.is_nan(), f"Not NaN, but {s.sum}")
        self.assertTrue(s.avg.is_nan(), f"Not NaN, but {s.avg}")
        self.assertTrue(s.max.is_nan(), f"Not NaN, but {s.max}")
        self.assertTrue(s.min.is_nan(), f"Not NaN, but {s.min}")
        self.assertTrue(s.median.is_nan(), f"Not NaN, but {s.median}")
        self.assertTrue(s.stdev.is_nan(), f"Not NaN, but {s.stdev}")

        s = StatValue.from_list([nan, v])
        self.assertTrue(s.sum.is_nan(), f"Not NaN, but {s.sum}")
        self.assertTrue(s.avg.is_nan(), f"Not NaN, but {s.avg}")
        self.assertTrue(s.max.is_nan(), f"Not NaN, but {s.max}")
        self.assertTrue(s.min.is_nan(), f"Not NaN, but {s.min}")
        self.assertTrue(s.median.is_nan(), f"Not NaN, but {s.median}")
        self.assertTrue(s.stdev.is_nan(), f"Not NaN, but {s.stdev}")
    def test_one_inf(self):
        inf = Decimal("inf")
        v = Decimal("0.123")

        s = StatValue.from_list([inf])
        self.assertEqual(s.sum, inf, "Not Inf, but " + str(s.sum))
        self.assertEqual(s.avg, inf, "Not Inf, but " + str(s.avg))
        self.assertEqual(s.max, inf, "Not Inf, but " + str(s.max))
        self.assertEqual(s.min, inf, "Not Inf, but " + str(s.min))
        self.assertEqual(s.median, inf, "Not Inf, but " + str(s.median))
        self.assertEqual(s.stdev, inf, "Not Inf, but " + str(s.stdev))

        s = StatValue.from_list([inf, v])
        self.assertEqual(s.sum, inf, "Not Inf, but " + str(s.sum))
        self.assertEqual(s.avg, inf, "Not NaN, but " + str(s.avg))
        self.assertEqual(s.max, inf, "Not NaN, but " + str(s.max))
        self.assertEqual(s.min, v, "Not NaN, but " + str(s.min))
        self.assertEqual(s.median, inf, "Not NaN, but " + str(s.median))
        self.assertEqual(s.stdev, inf, "Not NaN, but " + str(s.stdev))
Ejemplo n.º 6
0
    def test_one_inf(self):
        inf = Decimal("inf")
        v = Decimal("0.123")

        s = StatValue.from_list([inf])
        self.assertEqual(s.sum, inf, f"Not Inf, but {s.sum}")
        self.assertEqual(s.avg, inf, f"Not Inf, but {s.avg}")
        self.assertEqual(s.max, inf, f"Not Inf, but {s.max}")
        self.assertEqual(s.min, inf, f"Not Inf, but {s.min}")
        self.assertEqual(s.median, inf, f"Not Inf, but {s.median}")
        self.assertEqual(s.stdev, inf, f"Not Inf, but {s.stdev}")

        s = StatValue.from_list([inf, v])
        self.assertEqual(s.sum, inf, f"Not Inf, but {s.sum}")
        self.assertEqual(s.avg, inf, f"Not NaN, but {s.avg}")
        self.assertEqual(s.max, inf, f"Not NaN, but {s.max}")
        self.assertEqual(s.min, v, f"Not NaN, but {s.min}")
        self.assertEqual(s.median, inf, f"Not NaN, but {s.median}")
        self.assertEqual(s.stdev, inf, f"Not NaN, but {s.stdev}")
    def test_one_negative_inf(self):
        ninf = Decimal("-inf")
        inf = Decimal("inf")
        v = Decimal("0.123")

        s = StatValue.from_list([ninf])
        self.assertEqual(s.sum, ninf, "Not -Inf, but " + str(s.sum))
        self.assertEqual(s.avg, ninf, "Not -Inf, but " + str(s.avg))
        self.assertEqual(s.max, ninf, "Not -Inf, but " + str(s.max))
        self.assertEqual(s.min, ninf, "Not -Inf, but " + str(s.min))
        self.assertEqual(s.median, ninf, "Not -Inf, but " + str(s.median))
        self.assertEqual(s.stdev, inf, "Not Inf, but " + str(s.stdev))

        s = StatValue.from_list([ninf, v])
        self.assertEqual(s.sum, ninf, "Not -Inf, but " + str(s.sum))
        self.assertEqual(s.avg, ninf, "Not -Inf, but " + str(s.avg))
        self.assertEqual(s.max, v, "Not 0.123, but " + str(s.max))
        self.assertEqual(s.min, ninf, "Not -Inf, but " + str(s.min))
        self.assertEqual(s.median, ninf, "Not -Inf, but " + str(s.median))
        self.assertEqual(s.stdev, inf, "Not Inf, but " + str(s.stdev))
Ejemplo n.º 8
0
    def test_one_negative_inf(self):
        ninf = Decimal("-inf")
        inf = Decimal("inf")
        v = Decimal("0.123")

        s = StatValue.from_list([ninf])
        self.assertEqual(s.sum, ninf, f"Not -Inf, but {s.sum}")
        self.assertEqual(s.avg, ninf, f"Not -Inf, but {s.avg}")
        self.assertEqual(s.max, ninf, f"Not -Inf, but {s.max}")
        self.assertEqual(s.min, ninf, f"Not -Inf, but {s.min}")
        self.assertEqual(s.median, ninf, f"Not -Inf, but {s.median}")
        self.assertEqual(s.stdev, inf, f"Not Inf, but {s.stdev}")

        s = StatValue.from_list([ninf, v])
        self.assertEqual(s.sum, ninf, f"Not -Inf, but {s.sum}")
        self.assertEqual(s.avg, ninf, f"Not -Inf, but {s.avg}")
        self.assertEqual(s.max, v, f"Not 0.123, but {s.max}")
        self.assertEqual(s.min, ninf, f"Not -Inf, but {s.min}")
        self.assertEqual(s.median, ninf, f"Not -Inf, but {s.median}")
        self.assertEqual(s.stdev, inf, f"Not Inf, but {s.stdev}")
Ejemplo n.º 9
0
 def test_two_values(self):
     v1 = Decimal("1.23")
     v2 = Decimal("4.56")
     for t in [[v1, v2], [v2, v1]]:
         s = StatValue.from_list(t)
         self.assertEqual(s.sum, v1 + v2)
         self.assertEqual(s.avg, (v1 + v2) / Decimal(2))
         self.assertEqual(s.max, v2)
         self.assertEqual(s.min, v1)
         self.assertEqual(s.median, (v1 + v2) / Decimal(2))
         self.assertEqual(s.stdev, Decimal("1.665"))
    def test_multiple_positive_inf(self):
        inf = Decimal("inf")
        v = Decimal("0.123")

        # Equal number of infs
        s = StatValue.from_list([inf, inf, v])
        self.assertEqual(s.sum, inf, "Not Inf, but " + str(s.sum))
        self.assertEqual(s.avg, inf, "Not Inf, but " + str(s.avg))
        self.assertEqual(s.max, inf, "Not Inf, but " + str(s.max))
        self.assertEqual(s.min, v, "Not 0.123, but " + str(s.min))
        self.assertEqual(s.median, inf, "Not Inf, but " + str(s.median))
        self.assertEqual(s.stdev, inf, "Not Inf, but " + str(s.stdev))

        # Unequal number of infs
        s = StatValue.from_list([inf, inf, inf, v])
        self.assertEqual(s.sum, inf, "Not Inf, but " + str(s.sum))
        self.assertEqual(s.avg, inf, "Not Inf, but " + str(s.avg))
        self.assertEqual(s.max, inf, "Not Inf, but " + str(s.max))
        self.assertEqual(s.min, v, "Not 0.123, but " + str(s.min))
        self.assertEqual(s.median, inf, "Not Inf, but " + str(s.median))
        self.assertEqual(s.stdev, inf, "Not Inf, but " + str(s.stdev))
Ejemplo n.º 11
0
 def test_three_values(self):
     v1 = Decimal("0.123")
     v2 = Decimal("4.56")
     v3 = Decimal("789")
     for t in [[v1, v2, v3], [v3, v2, v1], [v2, v1, v3]]:
         s = StatValue.from_list(t)
         self.assertEqual(s.sum, v1 + v2 + v3)
         self.assertEqual(s.avg, (v1 + v2 + v3) / Decimal(3))
         self.assertEqual(s.max, v3)
         self.assertEqual(s.min, v1)
         self.assertEqual(s.median, v2)
         self.assertAlmostEqual(s.stdev, Decimal("370.83879721"))
Ejemplo n.º 12
0
    def test_multiple_positive_and_negative_inf(self):
        inf = Decimal("inf")
        ninf = Decimal("-inf")
        v = Decimal("0.123")

        s = StatValue.from_list([inf, ninf, v])
        self.assertTrue(s.sum.is_nan(), f"Not NaN, but {s.sum}")
        self.assertTrue(s.avg.is_nan(), f"Not NaN, but {s.avg}")
        self.assertEqual(s.max, inf, f"Not Inf, but {s.max}")
        self.assertEqual(s.min, ninf, f"Not -Inf, but {s.min}")
        self.assertEqual(s.median, v, f"Not 0.123, but {s.median}")
        self.assertTrue(s.stdev.is_nan(), f"Not NaN, but {s.stdev}")
Ejemplo n.º 13
0
    def test_multiple_positive_inf(self):
        inf = Decimal("inf")
        v = Decimal("0.123")

        # Equal number of infs
        s = StatValue.from_list([inf, inf, v])
        self.assertEqual(s.sum, inf, f"Not Inf, but {s.sum}")
        self.assertEqual(s.avg, inf, f"Not Inf, but {s.avg}")
        self.assertEqual(s.max, inf, f"Not Inf, but {s.max}")
        self.assertEqual(s.min, v, f"Not 0.123, but {s.min}")
        self.assertEqual(s.median, inf, f"Not Inf, but {s.median}")
        self.assertEqual(s.stdev, inf, f"Not Inf, but {s.stdev}")

        # Unequal number of infs
        s = StatValue.from_list([inf, inf, inf, v])
        self.assertEqual(s.sum, inf, f"Not Inf, but {s.sum}")
        self.assertEqual(s.avg, inf, f"Not Inf, but {s.avg}")
        self.assertEqual(s.max, inf, f"Not Inf, but {s.max}")
        self.assertEqual(s.min, v, f"Not 0.123, but {s.min}")
        self.assertEqual(s.median, inf, f"Not Inf, but {s.median}")
        self.assertEqual(s.stdev, inf, f"Not Inf, but {s.stdev}")
Ejemplo n.º 14
0
    def test_nan(self):
        import math

        nan = Decimal(float("nan"))
        v = Decimal(0.123)

        s = StatValue.from_list([nan])
        self.assertTrue(math.isnan(s.sum), "Not NaN, but " + str(s.sum))
        self.assertTrue(math.isnan(s.avg), "Not NaN, but " + str(s.avg))
        self.assertTrue(math.isnan(s.max), "Not NaN, but " + str(s.max))
        self.assertTrue(math.isnan(s.min), "Not NaN, but " + str(s.min))
        self.assertTrue(math.isnan(s.median), "Not NaN, but " + str(s.median))
        self.assertTrue(math.isnan(s.stdev), "Not NaN, but " + str(s.stdev))

        s = StatValue.from_list([nan, v])
        self.assertTrue(math.isnan(s.sum), "Not NaN, but " + str(s.sum))
        self.assertTrue(math.isnan(s.avg), "Not NaN, but " + str(s.avg))
        self.assertTrue(math.isnan(s.max), "Not NaN, but " + str(s.max))
        self.assertTrue(math.isnan(s.min), "Not NaN, but " + str(s.min))
        self.assertTrue(math.isnan(s.median), "Not NaN, but " + str(s.median))
        self.assertTrue(math.isnan(s.stdev), "Not NaN, but " + str(s.stdev))
    def test_multiple_negative_inf(self):
        ninf = Decimal("-inf")
        inf = Decimal("inf")
        v = Decimal("0.123")

        # Equal number of negative infs
        s = StatValue.from_list([ninf, ninf, v])
        self.assertEqual(s.sum, ninf, "Not -Inf, but " + str(s.sum))
        self.assertEqual(s.avg, ninf, "Not -Inf, but " + str(s.avg))
        self.assertEqual(s.max, v, "Not 0.123, but " + str(s.max))
        self.assertEqual(s.min, ninf, "Not -Inf, but " + str(s.min))
        self.assertEqual(s.median, ninf, "Not -Inf, but " + str(s.median))
        self.assertEqual(s.stdev, inf, "Not Inf, but " + str(s.stdev))

        # Unequal number of negative infs
        s = StatValue.from_list([ninf, ninf, ninf, v])
        self.assertEqual(s.sum, ninf, "Not -Inf, but " + str(s.sum))
        self.assertEqual(s.avg, ninf, "Not -Inf, but " + str(s.avg))
        self.assertEqual(s.max, v, "Not 0.123, but " + str(s.max))
        self.assertEqual(s.min, ninf, "Not -Inf, but " + str(s.min))
        self.assertEqual(s.median, ninf, "Not -Inf, but " + str(s.median))
        self.assertEqual(s.stdev, inf, "Not Inf, but " + str(s.stdev))
Ejemplo n.º 16
0
    def test_multiple_positive_and_negative_inf(self):
        import math

        inf = Decimal(float("inf"))
        ninf = Decimal(float("-inf"))
        v = Decimal(0.123)

        s = StatValue.from_list([inf, ninf, v])
        self.assertTrue(math.isnan(s.sum), "Not NaN, but " + str(s.sum))
        self.assertTrue(math.isnan(s.avg), "Not NaN, but " + str(s.avg))
        self.assertEqual(s.max, inf, "Not Inf, but " + str(s.max))
        self.assertEqual(s.min, ninf, "Not -Inf, but " + str(s.min))
        self.assertEqual(s.median, v, "Not 0.123, but " + str(s.median))
        self.assertTrue(math.isnan(s.stdev), "Not NaN, but " + str(s.stdev))
Ejemplo n.º 17
0
 def test_empty(self):
     self.assertIsNone(StatValue.from_list([]))