TimedXMLReader/TimedXMLReader.cpp

This sample is used as a simple benchmark for XML data processing.

00001 //
00002 //  Copyright (c) 2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 
00023 #include "stdafx.h"
00024 
00025 using namespace std;
00026 using namespace DWFCore;
00027 using namespace DWFToolkit;
00028 
00029 
00030 int main(int argc, char* argv[])
00031 {
00032 
00033     if (argc < 2)
00034     {
00035         wcout << L"Usage:" << argv[0] << L" file.dwf" << endl;
00036         return ( 0 );
00037     }
00038 
00039     try
00040     {
00041         DWFFile oDWF( argv[1] );
00042         DWFPackageReader oReader( oDWF );
00043 
00044         DWFPackageReader::tPackageInfo tInfo;
00045         oReader.getPackageInfo( tInfo );
00046 
00047         char zBuffer[4000] = {0};
00048 
00049         if (tInfo.eType != DWFPackageReader::eDWFPackage)
00050         {
00051             ::sprintf( zBuffer, "File is not a DWF package [%s]", 
00052                         (tInfo.eType == DWFPackageReader::eW2DStream) ? "W2D Stream" :
00053                         (tInfo.eType == DWFPackageReader::eDWFStream) ? "DWF Stream (<6.0)" :
00054                         (tInfo.eType == DWFPackageReader::eZIPFile) ? "ZIP Archive" : "Unknown" );
00055 
00056             cout << zBuffer << endl;
00057             exit( 0 );
00058         }
00059 
00060         ::sprintf( zBuffer, "DWF Package version [%0.2f]", (float)(tInfo.nVersion)/100.0f );
00061         cout << zBuffer << endl;
00062 
00063 
00064         cout << "Calibrating...";
00065 
00066 #ifdef  _DWFCORE_WIN32_SYSTEM
00067 
00068         size_t i = 0;
00069         unsigned long ms = ::GetTickCount();
00070         uint64_t ts = DWFTimer::Tick64();
00071         for(;i<999999999;i++){;}
00072         ts = DWFTimer::Tick64() - ts;
00073         ms = ::GetTickCount() - ms;
00074 
00075         double tpms = ts/(double)(ms);
00076 #else
00077 
00078         size_t i = 0;
00079         struct timeval tv;
00080         struct timeval tv2;
00081         gettimeofday( &tv, NULL );
00082         unsigned long long ts = DWFTimer::Tick64();
00083         for (;i<999999999;i++);
00084         ts = DWFTimer::Tick64() - ts;
00085         gettimeofday( &tv2, NULL );
00086 
00087         time_t sec = tv2.tv_sec - tv.tv_sec;
00088         suseconds_t usec = tv2.tv_usec - tv.tv_usec;
00089 
00090         double tpms = ts/( (sec*1000) + (usec/1000) );
00091 #endif
00092 
00093         cout << "using " << tpms << " ticks per ms" << endl << endl;
00094 
00095 
00096         DWFTimer oTimer;
00097         oTimer.start();
00098         DWFManifest& rManifest = oReader.getManifest();
00099         oTimer.stop();
00100 
00101 #ifdef  _DWFCORE_WIN32_SYSTEM
00102         uint64_t tick = oTimer.timer64();
00103 #else
00104         unsigned long long tick = oTimer.timer64();
00105 #endif
00106         double diff = tick/tpms;
00107 
00108         cout << "Read manifest [" << tick << " ticks] [~" << diff << " ms]" << endl;
00109 
00110         
00111         DWFSection* pSection = NULL;
00112 
00113         DWFManifest::SectionIterator* piSections = rManifest.getSections();
00114         
00115         if (piSections)
00116         {
00117             for (; piSections->valid(); piSections->next())
00118             {
00119                 pSection = piSections->get();
00120 
00121 
00122                 oTimer.start();
00123                 pSection->readDescriptor();
00124                 oTimer.stop();
00125 
00126 
00127                 tick = oTimer.timer64();
00128                 diff = tick/tpms;
00129 
00130                 cout << endl << "Read section descriptor [" << tick << " ticks] [~" << diff << " ms]" << endl;
00131 
00132                 DWFResourceContainer::ResourceIterator* piObjDefs = pSection->findResourcesByRole( DWFXML::kzRole_ObjectDefinition );
00133                 if (piObjDefs && piObjDefs->valid())
00134                 {
00135                     oTimer.start();
00136                     DWFObjectDefinition* pDef = pSection->getObjectDefinition();
00137                     oTimer.stop();
00138 
00139                     tick = oTimer.timer64();
00140                     diff = tick/tpms;
00141 
00142                     cout << "Processed object definition [" << tick << " ticks] [~" << diff << " ms]" << endl;
00143 
00144                     if (pDef)
00145                     {
00146                         DWFCORE_FREE_OBJECT( pDef );
00147                     }
00148 
00149                     DWFCORE_FREE_OBJECT( piObjDefs );
00150                 }
00151             }
00152             DWFCORE_FREE_OBJECT( piSections );
00153         }
00154 
00155         cout << "OK\n" << endl;
00156     }
00157     catch (DWFException& ex)
00158     {
00159         wcout << ex.type() << endl;
00160         wcout << ex.message() << endl;
00161         wcout << ex.function() << endl;
00162         wcout << ex.file() << endl;
00163         wcout << ex.line() << endl;
00164     }
00165 
00166         return 0;
00167 }
00168 
00169 

Generated on Tue Jan 6 22:40:01 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5