benchmark_stats.h (2361B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #ifndef TOOLS_BENCHMARK_BENCHMARK_STATS_H_ 7 #define TOOLS_BENCHMARK_BENCHMARK_STATS_H_ 8 9 #include <jxl/stats.h> 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #include <memory> 14 #include <string> 15 #include <vector> 16 17 namespace jpegxl { 18 namespace tools { 19 20 std::string StringPrintf(const char* format, ...); 21 22 struct JxlStats { 23 JxlStats() 24 : num_inputs(0), stats(JxlEncoderStatsCreate(), JxlEncoderStatsDestroy) {} 25 void Assimilate(const JxlStats& victim) { 26 num_inputs += victim.num_inputs; 27 JxlEncoderStatsMerge(stats.get(), victim.stats.get()); 28 } 29 void Print() const; 30 31 size_t num_inputs; 32 std::unique_ptr<JxlEncoderStats, decltype(JxlEncoderStatsDestroy)*> stats; 33 }; 34 35 // The value of an entry in the table. Depending on the ColumnType, the string, 36 // size_t or double should be used. 37 struct ColumnValue { 38 std::string s; // for TYPE_STRING 39 size_t i; // for TYPE_SIZE and TYPE_COUNT 40 double f; // for TYPE_POSITIVE_FLOAT 41 }; 42 43 struct BenchmarkStats { 44 void Assimilate(const BenchmarkStats& victim); 45 46 std::vector<ColumnValue> ComputeColumns(const std::string& codec_desc, 47 size_t corpus_size) const; 48 49 std::string PrintLine(const std::string& codec_desc, 50 size_t corpus_size) const; 51 52 void PrintMoreStats() const; 53 54 size_t total_input_files = 0; 55 size_t total_input_pixels = 0; 56 size_t total_compressed_size = 0; 57 size_t total_adj_compressed_size = 0; 58 double total_time_encode = 0.0; 59 double total_time_decode = 0.0; 60 float max_distance = -1.0; // Max butteraugli score 61 // sum of 8th powers of butteraugli distmap pixels. 62 double distance_p_norm = 0.0; 63 double psnr = 0.0; 64 double ssimulacra2 = 0.0; 65 std::vector<float> distances; 66 size_t total_errors = 0; 67 JxlStats jxl_stats; 68 std::vector<float> extra_metrics; 69 }; 70 71 std::string PrintHeader(const std::vector<std::string>& extra_metrics_names); 72 73 // Given the rows of all printed statistics, print an aggregate row. 74 std::string PrintAggregate( 75 size_t num_extra_metrics, 76 const std::vector<std::vector<ColumnValue>>& aggregate); 77 78 } // namespace tools 79 } // namespace jpegxl 80 81 #endif // TOOLS_BENCHMARK_BENCHMARK_STATS_H_