def test_aggregate(self): record_aggregator = RecordAggregator() # Insert 10 records for i in range(10): record_aggregator.insert( PerfThroughput(f"Throughput: {i} infer/sec\n\n\n\n")) # Aggregate them with max, min and average max_vals = record_aggregator.aggregate(record_types=[PerfThroughput], reduce_func=max) min_vals = record_aggregator.aggregate(record_types=[PerfThroughput], reduce_func=min) average = lambda seq: (sum(seq) * 1.0) / len(seq) average_vals = record_aggregator.aggregate( record_types=[PerfThroughput], reduce_func=average) self.assertEqual(max_vals[PerfThroughput], 9, msg="Aggregation failed with max") self.assertEqual(min_vals[PerfThroughput], 0, msg="Aggregation failed with min") self.assertEqual(average_vals[PerfThroughput], 4.5, msg="Aggregation failed with average")
def test_aggregate(self): record_aggregator = RecordAggregator() throughput_record = PerfThroughput(10) record_aggregator.insert(throughput_record) # Insert 10 records for i in range(9): record_aggregator.insert(PerfThroughput(i)) # Aggregate them with max, min and average max_vals = record_aggregator.aggregate( headers=[throughput_record.header()], reduce_func=max) min_vals = record_aggregator.aggregate( headers=[throughput_record.header()], reduce_func=min) average = lambda seq: (sum(seq) * 1.0) / len(seq) average_vals = record_aggregator.aggregate( headers=[throughput_record.header()], reduce_func=average) self.assertEqual(max_vals[throughput_record.header()], 10, msg="Aggregation failed with max") self.assertEqual(min_vals[throughput_record.header()], 0, msg="Aggregation failed with min") self.assertEqual(average_vals[throughput_record.header()], 4.6, msg="Aggregation failed with average")
def test_aggregate(self): record_aggregator = RecordAggregator() # Insert 10 records for i in range(10): record_aggregator.insert(PerfThroughput(i)) # Aggregate them with max, min and average max_vals = record_aggregator.aggregate(record_types=[PerfThroughput], reduce_func=max) min_vals = record_aggregator.aggregate(record_types=[PerfThroughput], reduce_func=min) def average(seq): return (sum(seq[1:], start=seq[0]) * 1.0) / len(seq) average_vals = record_aggregator.aggregate( record_types=[PerfThroughput], reduce_func=average) self.assertEqual(max_vals[PerfThroughput], PerfThroughput(9), msg="Aggregation failed with max") self.assertEqual(min_vals[PerfThroughput], PerfThroughput(0), msg="Aggregation failed with min") self.assertEqual(average_vals[PerfThroughput], PerfThroughput(4.5), msg="Aggregation failed with average")
def test_aggregate(self): record_aggregator = RecordAggregator() # Insert 10 records for i in range(10): record_aggregator.insert(PerfThroughput(i)) for i in range(10): record_aggregator.insert(GPUUtilization(i)) # Aggregate them with max, min and average max_vals = record_aggregator.aggregate(record_types=[PerfThroughput]) avg_vals = record_aggregator.aggregate(record_types=[GPUUtilization]) self.assertEqual(max_vals[PerfThroughput], PerfThroughput(9), msg="Aggregation failed with max") self.assertEqual(avg_vals[GPUUtilization], GPUUtilization(4.5), msg="Aggregation failed with max")