Commit 683092bb authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Benchmarks: refactored string types in logging

parent 5abc0c5c
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -23,13 +23,13 @@ class CustomLogging
{
public:
   CustomLogging( int verbose = true,
                  String outputMode = "",
                  std::string outputMode = "",
                  bool logFileAppend = false )
   : Logging(verbose), outputMode( outputMode )
   {}

   virtual void
   writeTitle( const String & title ) override
   writeTitle( const std::string & title ) override
   {
      if( verbose )
         std::cout << std::endl << "== " << title << " ==" << std::endl << std::endl;
@@ -61,7 +61,7 @@ public:
   }

   virtual void
   writeTableHeader( const String & spanningElement,
   writeTableHeader( const std::string & spanningElement,
                     const HeaderElements & subElements ) override
   {
      if( verbose && header_changed ) {
@@ -94,7 +94,7 @@ public:
   }

   virtual void
   writeTableRow( const String & spanningElement,
   writeTableRow( const std::string & spanningElement,
                  const RowElements & subElements ) override
   {
      if( verbose ) {
@@ -116,14 +116,14 @@ public:
      }

      // benchmark data are indented
      const String indent = "    ";
      const std::string indent = "    ";
      for( auto & it : subElements ) {
         log << indent << it << std::endl;
      }
   }

   virtual void
   writeErrorMessage( const char* msg ) override
   writeErrorMessage( const std::string& message ) override
   {
      // initial indent string
      log << std::endl;
@@ -136,7 +136,9 @@ public:
      for( auto & it : metadataColumns ) {
         log << it.second << std::endl;
      }
      log << msg << std::endl;

      // write the message
      log << message << std::endl;
   }

   virtual void
@@ -158,8 +160,8 @@ public:
   }

protected:
   // manual double -> String conversion with fixed precision
   static String
   // manual double -> string conversion with fixed precision
   static std::string
   _to_string( double num, int precision = 0, bool fixed = false )
   {
      std::stringstream str;
@@ -168,7 +170,7 @@ protected:
      if( precision )
         str << std::setprecision( precision );
      str << num;
      return String( str.str().data() );
      return std::string( str.str().data() );
   }

   std::stringstream log;
@@ -176,7 +178,7 @@ protected:
   MetadataColumns metadataColumns;
   bool header_changed = true;

   String outputMode;
   std::string outputMode;
};

} // namespace Benchmarks
+10 −10
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ class JsonLogging
{
public:
   JsonLogging( int verbose = true,
                String outputMode = "",
                std::string outputMode = "",
                bool logFileAppend = false )
   : Logging(verbose), outputMode( outputMode ), logFileAppend( logFileAppend )
   {}
@@ -97,7 +97,7 @@ public:
   }

   virtual void
   writeTitle( const String & title ) override
   writeTitle( const std::string & title ) override
   {
      if( outputMode == "append" )
         return;
@@ -125,22 +125,22 @@ public:
   }

   virtual void
   writeTableHeader( const String & spanningElement,
   writeTableHeader( const std::string & spanningElement,
                     const HeaderElements & subElements ) override
   {
   }

   virtual void
   writeTableRow( const String & spanningElement,
   writeTableRow( const std::string & spanningElement,
                  const RowElements & subElements ) override
   {
      writeRow( subElements );
   }

   virtual void
   writeErrorMessage( const char* msg ) override
   writeErrorMessage( const std::string& message ) override
   {
      log << "\"error\" : \"" << msg << "\"" << std::endl;
      log << "\"error\" : \"" << message << "\"" << std::endl;
   }

   virtual void
@@ -165,8 +165,8 @@ public:
   }

protected:
   // manual double -> String conversion with fixed precision
   static String
   // manual double -> string conversion with fixed precision
   static std::string
   _to_string( double num, int precision = 0, bool fixed = false )
   {
      std::stringstream str;
@@ -175,7 +175,7 @@ protected:
      if( precision )
         str << std::setprecision( precision );
      str << num;
      return String( str.str().data() );
      return std::string( str.str().data() );
   }

   std::stringstream log;
@@ -184,7 +184,7 @@ protected:
   LogsMetadata logsMetadata;
   WidthHints widthHints;
   CommonLogs commonLogs;
   String outputMode;
   std::string outputMode;

   bool lineStarted = false;
   bool resultsStarted = false;
+13 −15
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@
#include <string>
#include <sstream>

#include <TNL/String.h>

namespace TNL {
namespace Benchmarks {

@@ -72,7 +70,7 @@ class LoggingRowElements
      auto cend() const noexcept { return elements.cend(); }

   protected:
      std::list< String > elements;
      std::list< std::string > elements;

      std::stringstream stream;
};
@@ -80,14 +78,14 @@ class LoggingRowElements
class Logging
{
public:
   using MetadataElement = std::pair< const char*, String >;
   using MetadataMap = std::map< const char*, String >;
   using MetadataElement = std::pair< std::string, std::string >;
   using MetadataMap = std::map< std::string, std::string >;
   using MetadataColumns = std::vector< MetadataElement >;

   using HeaderElements = std::vector< String >;
   using HeaderElements = std::vector< std::string >;
   using RowElements = LoggingRowElements;

   using CommonLogs = std::vector< std::pair< const char*, String > >;
   using CommonLogs = MetadataColumns;
   using LogsMetadata = HeaderElements;
   using WidthHints = std::vector< int >;

@@ -106,7 +104,7 @@ public:
      return verbose;
   }

   virtual void writeTitle( const String & title ) = 0;
   virtual void writeTitle( const std::string& title ) = 0;

   virtual void addCommonLogs( const CommonLogs& logs ) = 0;

@@ -119,15 +117,15 @@ public:
   virtual void writeMetadata( const MetadataMap & metadata ) {}

   virtual void
   writeTableHeader( const String & spanningElement,
   writeTableHeader( const std::string& spanningElement,
                     const HeaderElements& subElements ) = 0;

   virtual void
   writeTableRow( const String & spanningElement,
   writeTableRow( const std::string& spanningElement,
                  const RowElements& subElements ) = 0;

   virtual void
   writeErrorMessage( const char* msg ) = 0;
   writeErrorMessage( const std::string& message ) = 0;

   virtual void closeTable() = 0;