@@ -122,6 +122,7 @@ bool rename_file(const std::string& old_filename, const std::string& new_filenam
122122static std::stringstream log_stream;
123123void write_log (bool );
124124void fix_quantities (IfcParse::IfcFile&, bool , bool , bool );
125+ std::string format_duration (time_t start, time_t end);
125126
126127// / @todo make the filters non-global
127128IfcGeom::entity_filter entity_filter; // Entity filter is used always by default.
@@ -475,10 +476,14 @@ int main(int argc, char** argv)
475476 int exit_code = EXIT_FAILURE;
476477 try {
477478 if (init_input_file (input_filename, ifc_file, no_progress || quiet, mmap)) {
479+ time_t start, end;
480+ time (&start);
478481 XmlSerializer s (ifc_file, output_temp_filename);
479482 Logger::Status (" Writing XML output..." );
480483 s.finalize ();
481- Logger::Status (" Done!" );
484+ time (&end);
485+ Logger::Status (" Done! Conversion took " + format_duration (start, end));
486+
482487 rename_file (output_temp_filename, output_filename);
483488 exit_code = EXIT_SUCCESS;
484489 }
@@ -786,28 +791,33 @@ int main(int argc, char** argv)
786791
787792 time (&end);
788793
789- if (!quiet) {
790- int seconds = (int )difftime (end, start);
791- std::stringstream msg;
792- int minutes = seconds / 60 ;
793- seconds = seconds % 60 ;
794- msg << " \n Conversion took" ;
795- if (minutes > 0 ) {
796- msg << " " << minutes << " minute" ;
797- if (minutes > 1 ) {
798- msg << " s" ;
799- }
800- }
801- msg << " " << seconds << " second" ;
802- if (seconds > 1 ) {
803- msg << " s" ;
804- }
805- Logger::Status (msg.str ());
806- }
794+ if (!quiet) {
795+ Logger::Status (" \n Conversion took " + format_duration (start, end));
796+ }
807797
808798 return successful ? EXIT_SUCCESS : EXIT_FAILURE;
809799}
810800
801+ std::string format_duration (time_t start, time_t end)
802+ {
803+ int seconds = (int )difftime (end, start);
804+ std::stringstream ss;
805+ int minutes = seconds / 60 ;
806+ seconds = seconds % 60 ;
807+ if (minutes > 0 ) {
808+ ss << minutes << " minute" ;
809+ if (minutes == 0 || minutes > 1 ) {
810+ ss << " s" ;
811+ }
812+ ss << " " ;
813+ }
814+ ss << seconds << " second" ;
815+ if (seconds == 0 || seconds > 1 ) {
816+ ss << " s" ;
817+ }
818+ return ss.str ();
819+ }
820+
811821void write_log (bool header) {
812822 std::string log = log_stream.str ();
813823 if (!log.empty ()) {
@@ -821,10 +831,12 @@ void write_log(bool header) {
821831#include < boost/algorithm/string/predicate.hpp>
822832
823833bool init_input_file (const std::string& filename, IfcParse::IfcFile*& ifc_file, bool no_progress, bool mmap) {
834+ time_t start, end;
824835
825836 // Prevent IfcFile::Init() prints by setting output to null temporarily
826837 if (no_progress) { Logger::SetOutput (NULL , &log_stream); }
827838
839+ time (&start);
828840#ifdef USE_MMAP
829841 ifc_file = new IfcParse::IfcFile (filename, mmap);
830842#else
@@ -841,8 +853,10 @@ bool init_input_file(const std::string& filename, IfcParse::IfcFile*& ifc_file,
841853 Logger::Error (" Unable to parse input file '" + filename + " '" );
842854 return false ;
843855 }
856+ time (&end);
844857
845858 if (no_progress) { Logger::SetOutput (&std::cout, &log_stream); }
859+ else { Logger::Status (" Parsing input file took " + format_duration (start, end)); }
846860
847861 return true ;
848862
0 commit comments