Просмотр исходного кода

Add new examples and tests (on execution duration)

Eric Ramat 11 лет назад
Родитель
Сommit
89b0f88ecc
2 измененных файлов с 178 добавлено и 12 удалено
  1. 60 12
      src/apps/main.cpp
  2. 118 0
      src/tests/mixed_tests.hpp

+ 60 - 12
src/apps/main.cpp

@@ -24,33 +24,61 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <boost/timer.hpp>
+
 #include <common/RootCoordinator.hpp>
 #include <common/scheduler/VectorScheduler.hpp>
 #include <common/scheduler/HeapScheduler.hpp>
 
 #include <tests/mixed_tests.hpp>
 
-void run_with_heap()
+void run_flat_with_heap()
 {
     paradevs::common::RootCoordinator <
         paradevs::MyTime, paradevs::pdevs::Coordinator <
             paradevs::MyTime,
             paradevs::common::scheduler::HeapScheduler < paradevs::MyTime >,
-            paradevs::RootGraphManager >
-        > rc(0, 10000, "root", paradevs::pdevs::Parameters());
+            paradevs::LinearGraphManager >
+        > rc(0, 500, "root", paradevs::pdevs::Parameters());
+
+    paradevs::common::Trace < paradevs::MyTime >::trace().clear();
+    rc.run();
+}
+
+void run_flat_with_vector()
+{
+    paradevs::common::RootCoordinator <
+        paradevs::MyTime, paradevs::pdevs::Coordinator <
+            paradevs::MyTime,
+            paradevs::common::scheduler::VectorScheduler < paradevs::MyTime >,
+            paradevs::LinearGraphManager >
+        > rc(0, 500, "root", paradevs::pdevs::Parameters());
+
+    paradevs::common::Trace < paradevs::MyTime >::trace().clear();
+    rc.run();
+}
+
+void run_hierarchic_with_heap()
+{
+    paradevs::common::RootCoordinator <
+        paradevs::MyTime, paradevs::pdevs::Coordinator <
+            paradevs::MyTime,
+            paradevs::common::scheduler::VectorScheduler < paradevs::MyTime >,
+            paradevs::Root2GraphManager >
+        > rc(0, 500, "root", paradevs::pdevs::Parameters());
 
     paradevs::common::Trace < paradevs::MyTime >::trace().clear();
     rc.run();
 }
 
-void run_with_vector()
+void run_hierarchic_with_vector()
 {
     paradevs::common::RootCoordinator <
         paradevs::MyTime, paradevs::pdevs::Coordinator <
             paradevs::MyTime,
             paradevs::common::scheduler::VectorScheduler < paradevs::MyTime >,
-            paradevs::RootGraphManager >
-        > rc(0, 10000, "root", paradevs::pdevs::Parameters());
+            paradevs::Root3GraphManager >
+        > rc(0, 500, "root", paradevs::pdevs::Parameters());
 
     paradevs::common::Trace < paradevs::MyTime >::trace().clear();
     rc.run();
@@ -58,11 +86,31 @@ void run_with_vector()
 
 int main()
 {
-    std::cout << "run_with_heap ..." << std::endl;
-    run_with_heap();
-    std::cout << "... OK" << std::endl;
-    std::cout << "run_with_vector ..." << std::endl;
-    run_with_vector();
-    std::cout << "... OK" << std::endl;
+    boost::timer t;
+
+    std::cout << "run_flat_with_heap ..." << std::endl;
+    run_flat_with_heap();
+
+    double t1 = t.elapsed();
+
+    std::cout << "... OK -> " << t1 << std::endl;
+    std::cout << "run_flat_with_vector ..." << std::endl;
+    run_flat_with_vector();
+
+    double t2 = t.elapsed();
+
+    std::cout << "... OK -> "  << (t2 - t1) << std::endl;
+    std::cout << "run_hierarchic_with_heap ..." << std::endl;
+    run_hierarchic_with_heap();
+
+    double t3 = t.elapsed();
+
+    std::cout << "... OK -> " << (t3 - t2) << std::endl;
+    std::cout << "run_hierarchic_with_vector ..." << std::endl;
+    run_hierarchic_with_vector();
+
+    double t4 = t.elapsed();
+
+    std::cout << "... OK -> "  << (t4 - t3) << std::endl;
     return 0;
 }

+ 118 - 0
src/tests/mixed_tests.hpp

@@ -423,4 +423,122 @@ private:
     dtss::Coordinator < MyTime, LastBagPolicy, S2GraphManager > S2;
 };
 
+class LinearGraphManager : public pdevs::GraphManager < MyTime >
+{
+public:
+    LinearGraphManager(common::Coordinator < MyTime >* coordinator) :
+        pdevs::GraphManager < MyTime >(coordinator)
+    {
+        for (unsigned int i = 1; i <= 200; ++i) {
+            std::ostringstream ss;
+
+            ss << "a" << i;
+            _models.push_back(new pdevs::Simulator < MyTime, A1 >(ss.str()));
+        }
+        for (unsigned int i = 0; i < 200; ++i) {
+            add_child(_models[i]);
+        }
+        for (unsigned int i = 0; i < 199; ++i) {
+            add_link(_models[i], "out", _models[i + 1], "in");
+        }
+    }
+
+    virtual ~LinearGraphManager()
+    {
+        for (unsigned int i = 0; i < 200; ++i) {
+            delete _models[i];
+        }
+    }
+
+private:
+    std::vector < pdevs::Simulator < MyTime, A1 >* > _models;
+};
+
+class Linear2GraphManager : public pdevs::GraphManager < MyTime >
+{
+public:
+    Linear2GraphManager(common::Coordinator < MyTime >* coordinator) :
+        pdevs::GraphManager < MyTime >(coordinator)
+    {
+        for (unsigned int i = 1; i <= 100; ++i) {
+            std::ostringstream ss;
+
+            ss << "a" << i;
+            _models.push_back(new pdevs::Simulator < MyTime, A1 >(ss.str()));
+        }
+        for (unsigned int i = 0; i < 100; ++i) {
+            add_child(_models[i]);
+        }
+        for (unsigned int i = 0; i < 99; ++i) {
+            add_link(_models[i], "out", _models[i + 1], "in");
+        }
+        add_link(coordinator, "in", _models[0], "in");
+        add_link(_models[99], "out", coordinator, "out");
+    }
+
+    virtual ~Linear2GraphManager()
+    {
+        for (unsigned int i = 0; i < 50; ++i) {
+            delete _models[i];
+        }
+    }
+
+private:
+    std::vector < pdevs::Simulator < MyTime, A1 >* > _models;
+};
+
+class Root2GraphManager : public pdevs::GraphManager < MyTime >
+{
+public:
+    Root2GraphManager(common::Coordinator < MyTime >* coordinator) :
+        pdevs::GraphManager < MyTime >(coordinator),
+        S1("S1", paradevs::pdevs::Parameters()),
+        S2("S2", paradevs::pdevs::Parameters())
+    {
+        add_child(&S1);
+        add_child(&S2);
+        add_link(&S1, "out", &S2, "in");
+    }
+
+    virtual ~Root2GraphManager()
+    { }
+
+private:
+    pdevs::Coordinator < MyTime,
+                         paradevs::common::scheduler::HeapScheduler <
+                             MyTime >,
+                         Linear2GraphManager > S1;
+    pdevs::Coordinator < MyTime,
+                         paradevs::common::scheduler::HeapScheduler <
+                             MyTime >,
+                         Linear2GraphManager > S2;
+};
+
+class Root3GraphManager : public pdevs::GraphManager < MyTime >
+{
+public:
+    Root3GraphManager(common::Coordinator < MyTime >* coordinator) :
+        pdevs::GraphManager < MyTime >(coordinator),
+        S1("S1", paradevs::pdevs::Parameters()),
+        S2("S2", paradevs::pdevs::Parameters())
+    {
+        add_child(&S1);
+        add_child(&S2);
+        add_link(&S1, "out", &S2, "in");
+    }
+
+    virtual ~Root3GraphManager()
+    { }
+
+private:
+    pdevs::Coordinator < MyTime,
+                         paradevs::common::scheduler::VectorScheduler <
+                             MyTime >,
+                         Linear2GraphManager > S1;
+    pdevs::Coordinator < MyTime,
+                         paradevs::common::scheduler::VectorScheduler <
+                             MyTime >,
+                         Linear2GraphManager > S2;
+};
+
 } // namespace paradevs