diff --git a/reader/JFJochCBFReader.cpp b/reader/JFJochCBFReader.cpp index 3b1edc7a4..7d554119f 100644 --- a/reader/JFJochCBFReader.cpp +++ b/reader/JFJochCBFReader.cpp @@ -8,8 +8,10 @@ #include #include #include +#include #include #include +#include #include "../common/JFJochException.h" #include "../common/Logger.h" @@ -258,10 +260,21 @@ void JFJochCBFReader::ReadFiles(const std::string &path) { std::chrono::duration_cast( std::chrono::duration(header0_.exposure_s))); - // The rotation angle of every image, from its own header. + // The rotation angle of every image, from its own header. Parsing one costs a few hundred + // microseconds - it is two dozen regular expressions - so on a sweep of several thousand frames + // this is seconds of startup before a single image is read, and the files are independent. std::vector angles(files_.size()); - for (size_t i = 0; i < files_.size(); i++) - angles[i] = minicbf::ReadHeader(files_[i]).start_angle_deg; + { + const size_t nthreads = std::min(std::max(1u, std::thread::hardware_concurrency()), 8); + std::vector> futures; + for (size_t t = 0; t < nthreads; t++) + futures.push_back(std::async(std::launch::async, [&, t] { + for (size_t i = t; i < files_.size(); i += nthreads) + angles[i] = minicbf::ReadHeader(files_[i]).start_angle_deg; + })); + for (auto &f : futures) + f.get(); + } double increment = header0_.angle_increment_deg; if (files_.size() > 1) {