-
Notifications
You must be signed in to change notification settings - Fork 0
Add libjpeg vs libjpegturbo benchmark #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2b06100
bc4bebe
66c87cc
60b48c3
029efb3
e0362c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||||||||||||||
| #include <chrono> | ||||||||||||||||||||||||||
| #include <iterator> | ||||||||||||||||||||||||||
| #include <numeric> | ||||||||||||||||||||||||||
| #include "absl/flags/flag.h" | ||||||||||||||||||||||||||
| #include "absl/flags/internal/flag.h" | ||||||||||||||||||||||||||
| #include "absl/flags/parse.h" | ||||||||||||||||||||||||||
|
nanoticity marked this conversation as resolved.
|
||||||||||||||||||||||||||
| #include "src/utils/log.h" | ||||||||||||||||||||||||||
| #include "src/utils/pch.h" | ||||||||||||||||||||||||||
| #include <sstream> | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ABSL_FLAG(std::string, image_path, "path/to/image.jpg", // NOLINT | ||||||||||||||||||||||||||
| "Path to the image file to be loaded and decoded."); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ABSL_FLAG(uint, num_trials, 10000, "Number of decoding trials to perform."); // NOLINT | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| auto loadImage(const std::string& path) -> std::vector<uchar> { | ||||||||||||||||||||||||||
| std::ifstream file(path, std::ios::binary); | ||||||||||||||||||||||||||
| if (!file) { | ||||||||||||||||||||||||||
| LOG(FATAL) << "Image could not be loaded from path '" << path | ||||||||||||||||||||||||||
| << "'; path invalid or image doesn't exist."; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| std::vector<uchar> data(std::istreambuf_iterator<char>(file), {}); | ||||||||||||||||||||||||||
| return data; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| auto decodeImage(const std::vector<uchar>& raw) -> cv::Mat { | ||||||||||||||||||||||||||
| cv::Mat decoded = cv::imdecode(raw, cv::IMREAD_COLOR); | ||||||||||||||||||||||||||
| return decoded; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| auto main(int argc, char** argv) -> int { | ||||||||||||||||||||||||||
| absl::ParseCommandLine(argc, argv); | ||||||||||||||||||||||||||
| std::string imagePath = absl::GetFlag(FLAGS_image_path); | ||||||||||||||||||||||||||
| std::vector<uchar> rawImageData = loadImage(imagePath); | ||||||||||||||||||||||||||
| // print which jpeg library we are using so that we know and don't get mixed up | ||||||||||||||||||||||||||
| std::istringstream stream(cv::getBuildInformation()); | ||||||||||||||||||||||||||
| std::string line; | ||||||||||||||||||||||||||
| while (std::getline(stream, line)) { | ||||||||||||||||||||||||||
| if (line.find("jpeg:") != std::string::npos || | ||||||||||||||||||||||||||
| line.find("JPEG:") != std::string::npos) { | ||||||||||||||||||||||||||
| LOG(INFO) << line; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| const uint tests = absl::GetFlag(FLAGS_num_trials); | ||||||||||||||||||||||||||
| std::vector<double> trials; | ||||||||||||||||||||||||||
| for (uint i = 0; i < tests; ++i) { | ||||||||||||||||||||||||||
| auto start = std::chrono::high_resolution_clock::now(); | ||||||||||||||||||||||||||
| cv::Mat decodedImage = decodeImage(rawImageData); | ||||||||||||||||||||||||||
| auto end = std::chrono::high_resolution_clock::now(); | ||||||||||||||||||||||||||
| if (decodedImage.empty()) { | ||||||||||||||||||||||||||
| LOG(INFO) << "image decode failed"; | ||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| double ms = std::chrono::duration<double, std::milli>(end - start).count(); | ||||||||||||||||||||||||||
| trials.push_back(ms); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
nanoticity marked this conversation as resolved.
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| double total = std::accumulate(trials.begin(), trials.end(), 0.0); | ||||||||||||||||||||||||||
| double average = total / trials.size(); | ||||||||||||||||||||||||||
| LOG(INFO) << "Average decoding time over " << tests << " trials: " << average | ||||||||||||||||||||||||||
| << " ms"; | ||||||||||||||||||||||||||
|
Comment on lines
+58
to
+61
|
||||||||||||||||||||||||||
| double total = std::accumulate(trials.begin(), trials.end(), 0.0); | |
| double average = total / trials.size(); | |
| LOG(INFO) << "Average decoding time over " << tests << " trials: " << average | |
| << " ms"; | |
| const size_t successful_decodes = trials.size(); | |
| if (successful_decodes == 0) { | |
| LOG(FATAL) << "All " << tests << " image decode attempts failed."; | |
| } | |
| double total = std::accumulate(trials.begin(), trials.end(), 0.0); | |
| double average = total / successful_decodes; | |
| LOG(INFO) << "Average decoding time over " << successful_decodes | |
| << " successful trials: " << average << " ms"; |
Uh oh!
There was an error while loading. Please reload this page.