Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoBoardCheckPerformance.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file GoBoardCheckPerformance.cpp
00003     See GoBoardCheckPerformance.h */
00004 //----------------------------------------------------------------------------
00005 
00006 #include "SgSystem.h"
00007 #include "GoBoardCheckPerformance.h"
00008 
00009 #include <fstream>
00010 #include "GoBoard.h"
00011 #include "GoBoardUtil.h"
00012 #include "SgTime.h"
00013 
00014 using namespace std;
00015 
00016 //----------------------------------------------------------------------------
00017 
00018 void GoBoardCheckPerformance::CheckPerformance(const GoBoard& board,
00019                                                ostream& out)
00020 {
00021     const int NUM_REPETITIONS = 10000;
00022     int i;
00023 
00024     double startTime = SgTime::Get();
00025     int sum1 = 0;
00026     for (i = 0; i < NUM_REPETITIONS; ++i)
00027     {
00028         for (SgPoint p = 0; p < SG_MAXPOINT; ++p)
00029         {   if (board.IsEmpty(p))
00030                 sum1 += p;
00031         }
00032     }
00033     double endTime1 = SgTime::Get();
00034 
00035     int sum2 = 0;
00036     for (i = 0; i < NUM_REPETITIONS; ++i)
00037     {
00038         for (SgPoint p = board.FirstBoardPoint(); p <= board.LastBoardPoint();
00039              ++p)
00040         {   if (board.IsEmpty(p))
00041                 sum2 += p;
00042         }
00043     }
00044     double endTime2 = SgTime::Get();
00045 
00046     int sum3 = 0;
00047     for (i = 0; i < NUM_REPETITIONS; ++i)
00048         for (GoBoard::Iterator it(board); it; ++it)
00049         {
00050             if (board.IsEmpty(*it))
00051                 sum3 += *it;
00052         }
00053     double endTime3 = SgTime::Get();
00054 
00055     int sum4 = 0;
00056     for (i = 0; i < NUM_REPETITIONS; ++i)
00057     {
00058         for (SgPoint p = 0; p < SG_MAXPOINT; ++p)
00059         {
00060             if (board.IsEmpty(p))
00061                 sum4 += p;
00062         }
00063     }
00064     double endTime4 = SgTime::Get();
00065 
00066     int sum5 = 0;
00067     for (i = 0; i < NUM_REPETITIONS; ++i)
00068     {
00069         for (SgPoint p = board.FirstBoardPoint(); p <= board.LastBoardPoint();
00070              ++p)
00071         {
00072             if (board.IsEmpty(p))
00073                 sum5 += p;
00074         }
00075     }
00076     double endTime5 = SgTime::Get();
00077 
00078     SG_ASSERT(sum1 == sum2);
00079     SG_ASSERT(sum2 == sum3);
00080     SG_ASSERT(sum3 == sum4);
00081     SG_ASSERT(sum4 == sum5);
00082 
00083     double time1 = endTime1 - startTime;
00084     double time2 = endTime2 - endTime1;
00085     double time3 = endTime3 - endTime2;
00086     double time4 = endTime4 - endTime3;
00087     double time5 = endTime5 - endTime4;
00088 
00089     out << "Time1: " << time1 << " For 0..SG_MAXPOINT\n"
00090         << "Time2: " << time2 << " First/LastBoardPoint\n"
00091         << "Time3: " << time3 << " GoBoard::Iterator\n"
00092         << "Time4: " << time4 << " For 0..SG_MAXPOINT, no dependency\n"
00093         << "Time5: " << time5 << " First/LastBoardPoint, no dependency\n";
00094 }


Sun Mar 13 2011 Doxygen 1.7.1