speed_stats.h (1409B)
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_SPEED_STATS_H_ 7 #define TOOLS_SPEED_STATS_H_ 8 9 #include <stddef.h> 10 #include <stdint.h> 11 12 #include <vector> 13 14 namespace jpegxl { 15 namespace tools { 16 17 class SpeedStats { 18 public: 19 void NotifyElapsed(double elapsed_seconds); 20 21 struct Summary { 22 // How central_tendency was computed - depends on number of reps. 23 const char* type; 24 25 // Elapsed time 26 double central_tendency; 27 double min; 28 double max; 29 double variability; 30 }; 31 32 // Non-const, may sort elapsed_. 33 bool GetSummary(Summary* summary); 34 35 // Sets the image size to allow computing MP/s values. 36 void SetImageSize(size_t xsize, size_t ysize) { 37 xsize_ = xsize; 38 ysize_ = ysize; 39 } 40 41 // Sets the file size to allow computing MB/s values. 42 void SetFileSize(size_t file_size) { file_size_ = file_size; } 43 44 // Calls GetSummary and prints megapixels/sec. SetImageSize() must be called 45 // once before this can be used. 46 bool Print(size_t worker_threads); 47 48 private: 49 std::vector<double> elapsed_; 50 size_t xsize_ = 0; 51 size_t ysize_ = 0; 52 53 // Size of the source binary file, meaningful when decoding a recompressed 54 // JPEG. 55 size_t file_size_ = 0; 56 }; 57 58 } // namespace tools 59 } // namespace jpegxl 60 61 #endif // TOOLS_SPEED_STATS_H_