[opengtl-commits] [372] benchmark for different levels of optimization

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 372
Author:   cyrille
Date:     2008-09-07 10:17:51 +0200 (Sun, 07 Sep 2008)

Log Message:
-----------
benchmark for different levels of optimization

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/tools/benchmark/CtlBenchmark.cpp


Modified: trunk/OpenGTL/OpenCTL/tools/benchmark/CtlBenchmark.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/tools/benchmark/CtlBenchmark.cpp	2008-09-07 07:38:53 UTC (rev 371)
+++ trunk/OpenGTL/OpenCTL/tools/benchmark/CtlBenchmark.cpp	2008-09-07 08:17:51 UTC (rev 372)
@@ -25,6 +25,7 @@
 #include <vector>
 
 #include <GTLCore/Array.h>
+#include <GTLCore/Optimiser.h>
 #include <GTLCore/PixelDescription.h>
 #include <GTLCore/Type.h>
 
@@ -160,7 +161,7 @@
 
 class CtlBenchmark : public Benchmark {
   protected:
-    CtlBenchmark(const std::vector< PointF >& _points, int runCount, GTLCore::Array* array ) : Benchmark(runCount, array ), points(_points), program(0) {}
+    CtlBenchmark(int _level, const std::vector< PointF >& _points, int runCount, GTLCore::Array* array ) : Benchmark(runCount, array ), points(_points), program(0) {}
     GTLCore::String sourceCode() const;
     void compile();
     void apply();
@@ -168,19 +169,21 @@
      GTLCore::String valueListToCTL( const std::vector<PointF>& _points, double _scale ) const;
      std::vector< PointF > points;
      OpenCTL::Program* program;
+     int m_level;
 };
 
 void CtlBenchmark::compile()
 {
-    OpenCTL::Module p("");
-    p.setSource( sourceCode() );
-    p.compile();
-    if(not p.isCompiled())
-    {
-      std::cout << "Error: " << std::endl << p.compilationErrorsMessage() << std::endl;
-      abort();
-    }
-    program = new OpenCTL::Program( "apply", &p, GTLCore::PixelDescription( GTLCore::Type::Float, 4) );
+  GTLCore::Optimiser::instance()->setLevel( m_level );
+  OpenCTL::Module p("");
+  p.setSource( sourceCode() );
+  p.compile();
+  if(not p.isCompiled())
+  {
+    std::cout << "Error: " << std::endl << p.compilationErrorsMessage() << std::endl;
+    abort();
+  }
+  program = new OpenCTL::Program( "apply", &p, GTLCore::PixelDescription( GTLCore::Type::Float, 4) );
 }
 
 void CtlBenchmark::apply()
@@ -208,9 +211,9 @@
   GTLCore::String program16Src = "const float lightTable[][2] = " + valueListToCTL( points, 1.0 ) + ";";
   program16Src += "void apply( float rIn, float gIn, float bIn, float aIn, output float rOut, output float gOut, output float bOut, output float aOut) \
   { \
-      rOut = interpolateCubic1D( lightTable, rIn); \
-      gOut = interpolateCubic1D( lightTable, gIn); \
-      bOut = interpolateCubic1D( lightTable, bIn); \
+      rOut = interpolateCubic1D( lightTable, interpolateCubic1D( lightTable, rIn) ); \
+      gOut = interpolateCubic1D( lightTable, interpolateCubic1D( lightTable, gIn) ); \
+      bOut = interpolateCubic1D( lightTable, interpolateCubic1D( lightTable, bIn) ); \
       aOut = aIn; \
   }";
   return program16Src;
@@ -218,7 +221,7 @@
 
 class CompileEachTimeCtlBenchmark : public CtlBenchmark {
   public:
-    CompileEachTimeCtlBenchmark(const std::vector< PointF >& points, int runCount, GTLCore::Array* array ) : CtlBenchmark(points, runCount, array ) {}
+    CompileEachTimeCtlBenchmark(int _level, const std::vector< PointF >& points, int runCount, GTLCore::Array* array ) : CtlBenchmark(_level, points, runCount, array ) {}
   protected:
     virtual void initialise()
     {
@@ -232,7 +235,7 @@
 
 class CompileOnceCtlBenchmark : public CtlBenchmark {
   public:
-    CompileOnceCtlBenchmark(const std::vector< PointF >& points, int runCount, GTLCore::Array* array ) : CtlBenchmark(points, runCount, array ) {}
+    CompileOnceCtlBenchmark(int _level, const std::vector< PointF >& points, int runCount, GTLCore::Array* array ) : CtlBenchmark(_level, points, runCount, array ) {}
   protected:
     virtual void initialise()
     {
@@ -276,16 +279,18 @@
   GTLCore::PixelDescription pd( GTLCore::Type::Float, 4);
   GTLCore::Array array( 1000000 * pd.bitsSize() / 8 );
   
+  for(int level = 0; level <= GTLCore::Optimiser::maximumRecommendedLevel(); ++level)
   {
-    std::cout << "Compile once " << std::endl;
-    CompileOnceCtlBenchmark benchmark(points, 100, &array);
+    std::cout << "Compile once = " << level << std::endl;
+    CompileOnceCtlBenchmark benchmark(level, points, 100, &array);
     benchmark.start();
     benchmark.dump();
   }
   
+  for(int level = 0; level <= GTLCore::Optimiser::maximumRecommendedLevel(); ++level)
   {
-    std::cout << "Compile each time " << std::endl;
-    CompileEachTimeCtlBenchmark benchmark(points, 100, &array);
+    std::cout << "Compile each time for level = " << level << std::endl;
+    CompileEachTimeCtlBenchmark benchmark(level, points, 100, &array);
     benchmark.start();
     benchmark.dump();
   }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/