pauldick    01/02/13 07:15:53

  Modified:    c/Tests/Performance perf.cpp
  Log:
  Major overhaul.  Now reads in parameters and will exclude certain
  files if specified by "-s"
  
  Revision  Changes    Path
  1.9       +235 -229  xml-xalan/c/Tests/Performance/perf.cpp
  
  Index: perf.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/Tests/Performance/perf.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- perf.cpp  2001/02/07 15:37:37     1.8
  +++ perf.cpp  2001/02/13 15:15:50     1.9
  @@ -121,10 +121,20 @@
   
   const char* const    excludeStylesheets[] =
   {
  -     "d:\\xslt\\xsl-test\\perf\\large\\large-evans_large",
  +     "large-evans_large.xml",
        0
   };
   
  +inline bool
  +checkForExclusion(XalanDOMString currentFile)
  +{
  +
  +             for (int i=0; excludeStylesheets[i] != 0; i++)
  +                     {       if (equals(currentFile, 
XalanDOMString(excludeStylesheets[i])))
  +                             return true;
  +                     }
  +             return false;
  +}
   
   inline StylesheetRoot*
   processStylesheet(
  @@ -226,6 +236,33 @@
        return endTime - startTime;
   }
   
  +void
  +getParams(int argc, 
  +               const char*   argv[], 
  +               long& iterCount, 
  +               bool& skip)
  +{
  +     if (argc >= 4 )
  +     {
  +             cout << "Usage perf {count, -s(kip)} " << endl;
  +             exit(1);
  +     }
  +     if (argc >= 2)
  +     {
  +             iterCount = atol(argv[1]);
  +             if (iterCount <= 0)
  +             {
  +                     cerr << "Usage: perf <count, -s(kip)>" << endl  << endl;
  +                     exit(1);
  +             }
  +             if (argc >= 3 && !stricmp(argv[2], "-s"))
  +             {
  +                     skip = true;
  +             }
  +             return;
  +     }                       
  +}
  +
   #if defined(XALAN_NO_NAMESPACES)
        typedef vector<XalanDOMString>          FileNameVectorType;
   #else
  @@ -238,6 +275,13 @@
         const char*    argv[])
   {
   
  +     long iterCount = 5;     // Default number of iterations
  +     bool skip = false;      // Default will not skip long tests
  +
  +     // Defined root for performance directory. Based on PD's machine. 
  +     const XalanDOMString    
perfDir(XALAN_STATIC_UCODE_STRING("d:\\xslt\\xsl-test\\perf\\"));
  +
  +
   #if !defined(NDEBUG) && defined(_MSC_VER)
        _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | 
_CRTDBG_LEAK_CHECK_DF);
   
  @@ -248,155 +292,126 @@
        FileUtility f;
        FileNameVectorType dirs, files;
   
  -     // Defined root for performance directory. Based on PD's machine.
  -     // At some point this should be a setting in a prop file
  -     // or an arguement to the program. 
  -     const XalanDOMString    
perfDir(XALAN_STATIC_UCODE_STRING("d:\\xslt\\xsl-test\\perf\\"));
  -
        // Get the list of Directories that are below perf
        dirs = f.getDirectoryNames(perfDir);
   
        XMLFileReporter logFile("cpp.xml");
  -
  -//   logFile.setFileName("cpp.xml");
  -//   logFile.initialize();
        logFile.logTestFileInit("Performance Testing - Reports performance 
times for single transform, and average for multiple transforms using compiled 
stylesheet");
   
  -     if (argc > 3)
  -     {
  -             cerr << "Usage: perf <count>" << endl  << endl;
  -     }
  -     else
  +     getParams(argc, argv, iterCount, skip);
  +     try
        {
  -             long iterCount = 1;
  -             if (argc == 2)
  +             // Call the static initializers... and define file suffixes
  +             XMLPlatformUtils::Initialize();
                {
  -                     iterCount = atol(argv[1]);
  -             }
  +                     XSLTInit        theInit;
  +                     
  +                     // Define some constants for file suffixes ...
  +                     const XalanDOMString  XSLSuffix(".xsl");
  +                     const XalanDOMString  XMLSuffix(".xml");
  +                     const XalanDOMString  
outputDir("\\xslt-results\\perf\\test\\");
  +                     const XalanDOMString  
pathSep(XALAN_STATIC_UCODE_STRING("\\"));  
  +                     const XalanDOMString  outputSuffix(".out");
  +
  +                     // Define some variables used for timing...
  +                     clock_t startTime, endTime, accmTime;
  +                     double timeinMilliseconds, theAverage;
   
  -             if (iterCount <= 0)
  -             {
  -                     cerr << "Usage: perf <count>" << endl  << endl;
  -             }
  -             else
  -             {
  -                     try
  -                     {
  -                             // Call the static initializers... and define 
file suffixes
  -                             XMLPlatformUtils::Initialize();
   
  +                     for(FileNameVectorType::size_type       j = 0; j < 
dirs.size(); j++)
  +                     {
  +                       files = f.getTestFileNames(perfDir, dirs[j]);
  +                       for(FileNameVectorType::size_type i = 0; i < 
files.size(); i++)
  +                       {
  +                             if (skip)
                                {
  -                                     XSLTInit        theInit;
  -                                     
  -                                     // Define some constants for file 
suffixes ...
  -                                     const XalanDOMString  XSLSuffix(".xsl");
  -                                     const XalanDOMString  XMLSuffix(".xml");
  -                                     const XalanDOMString  
outputDir("\\xslt-results\\perf\\test\\");
  -                                     const XalanDOMString  
pathSep(XALAN_STATIC_UCODE_STRING("\\"));  
  -                                     const XalanDOMString  
outputSuffix(".out");
  -
  -                                     // Define some variables used for 
timing...
  -                                     clock_t startTime, endTime, accmTime;
  -                    double timeinMilliseconds, theAverage;
  -
  -
  -                                     for(FileNameVectorType::size_type       
j = 0; j < dirs.size(); j++)
  +                                     if (checkForExclusion(files[i]))
                                        {
  -                                       files = f.getTestFileNames(perfDir, 
dirs[j]);
  +                                             continue;
  +                                     }
  +                             }
  +                             // Output file name to result log.
  +                             logFile.logTestCaseInit(files[i]);
   
  -                                       for(FileNameVectorType::size_type i = 
0; i < files.size(); i++)
  -                                       {
  -                                             // Output file name to result 
log.
  -                                             
logFile.logTestCaseInit(files[i]);
  -
  -                                             const XalanDOMString  
theXMLFile= perfDir + dirs[j] + pathSep + files[i];
  -                                             const XalanDOMString  
theXSLFile = f.GenerateFileName(theXMLFile,"xsl");
  -                                             const XalanDOMString  
theOutputFile = f.GenerateFileName(theXMLFile, "out");
  -
  -
  -                                             // Create the necessary support 
objects to instantiate a processor.
  -                                             XalanSourceTreeDOMSupport       
        csDOMSupport;
  -                                             XalanSourceTreeParserLiaison    
csParserLiaison(csDOMSupport);
  -
  -                                             
csDOMSupport.setParserLiaison(&csParserLiaison);
  -
  -                                             XSLTProcessorEnvSupportDefault  
csXSLTProcessorEnvSupport;
  -                                             XObjectFactoryDefault           
        csXObjectFactory;
  -                                             XPathFactoryDefault             
                csXPathFactory;
  -
  -                                             // Create a processor and 
connect to ProcessorEnvSupport object
  -                                             XSLTEngineImpl  csProcessor(
  -                                                             csParserLiaison,
  -                                                             
csXSLTProcessorEnvSupport,
  -                                                             csDOMSupport,
  -                                                             
csXObjectFactory,
  -                                                             csXPathFactory);
  -
  -                                             // Hook up the processor the 
the support object.
  -                                             
csXSLTProcessorEnvSupport.setProcessor(&csProcessor);
  -
  -                                             // Create separate factory 
support object, so the stylesheet's
  -                                             // factory-created XPath 
instance are independent from processor's.
  -                                             XPathFactoryDefault             
        ssXPathFactory;
  -
  -                                             // Create a stylesheet 
construction context, using the
  -                                             // stylesheet's factory support 
objects.
  -                                             
StylesheetConstructionContextDefault    csConstructionContext(
  +                             const XalanDOMString  theXMLFile= perfDir + 
dirs[j] + pathSep + files[i];
  +                             const XalanDOMString  theXSLFile = 
f.GenerateFileName(theXMLFile,"xsl");
  +                             const XalanDOMString  theOutputFile = 
f.GenerateFileName(theXMLFile, "out");
  +
  +
  +                             // Create the necessary support objects to 
instantiate a processor.
  +                             XalanSourceTreeDOMSupport               
csDOMSupport;
  +                             XalanSourceTreeParserLiaison    
csParserLiaison(csDOMSupport);
  +
  +                             csDOMSupport.setParserLiaison(&csParserLiaison);
  +
  +                             XSLTProcessorEnvSupportDefault  
csXSLTProcessorEnvSupport;
  +                             XObjectFactoryDefault                   
csXObjectFactory;
  +                             XPathFactoryDefault                             
csXPathFactory;
  +
  +                             // Create a processor and connect to 
ProcessorEnvSupport object
  +                             XSLTEngineImpl  csProcessor(
  +                                                     csParserLiaison,
  +                                                     
csXSLTProcessorEnvSupport,
  +                                                     csDOMSupport,
  +                                                     csXObjectFactory,
  +                                                     csXPathFactory);
  +
  +                             // Hook up the processor the the support object.
  +                             
csXSLTProcessorEnvSupport.setProcessor(&csProcessor);
  +
  +                             // Create separate factory support object, so 
the stylesheet's
  +                             // factory-created XPath instance are 
independent from processor's.
  +                             XPathFactoryDefault                     
ssXPathFactory;
  +
  +                             // Create a stylesheet construction context, 
using the
  +                             // stylesheet's factory support objects.
  +                             StylesheetConstructionContextDefault    
csConstructionContext(
  +                                                                             
                                csProcessor,
  +                                                                             
                                csXSLTProcessorEnvSupport,
  +                                                                             
                                ssXPathFactory);
  +                             cout << endl << files[i] << endl;
  +
  +                             // Create a parsed stylesheet (StylesheetRoot) 
for the
  +                             // specified input XSL. We don't have to delete 
it, since
  +                             // it is owned by the 
StylesheetConstructionContextDefault
  +                             // instance. Time it as well...
  +
  +                             startTime = clock();
  +                             const StylesheetRoot* const glbStylesheetRoot = 
processStylesheet(
  +                                                                             
                                                theXSLFile,
                                                                                
                                                csProcessor,
  -                                                                             
                                                csXSLTProcessorEnvSupport,
  -                                                                             
                                                ssXPathFactory);
  -
  -
  -                                             cout << endl << files[i] << 
endl;
  -
  -
  -                                             // Create a parsed stylesheet 
(StylesheetRoot) for the
  -                                             // specified input XSL. We 
don't have to delete it, since
  -                                             // it is owned by the 
StylesheetConstructionContextDefault
  -                                             // instance. Time it as well...
  -
  -                                             startTime = clock();
  -                                             const StylesheetRoot* const 
glbStylesheetRoot =
  -                                                                     
processStylesheet(
  -                                                                             
theXSLFile,
  -                                                                             
csProcessor,
  -                                                                             
csConstructionContext);
  -                                             endTime = clock();
  -                                             assert(glbStylesheetRoot != 0);
  -
  -                                             // Calculate & report 
performance on stylesheet parse to console and log file.
  -                                             timeinMilliseconds = 
calculateElapsedTime(startTime, endTime);
  -                                             cout << "   XSL parse: " << 
timeinMilliseconds << " milliseconds." << endl;
  -                                             logFile.logStatistic(
  -                                                             60,
  -                                                             
long(timeinMilliseconds),
  -                                                             
timeinMilliseconds,
  -                                                             "Parse of XSL: 
");
  -
  -
  -                                             // Parse the input XML and 
report how long it took...                             
  -
  -                                             startTime = clock();
  -                                             XalanNode* const        
glbSourceXML = parseSourceDocument(theXMLFile, csProcessor);
  -                                             endTime = clock();
  -
  -                                             // Calculate & report 
performance on source document parse to console and log file.
  -                                             timeinMilliseconds = 
calculateElapsedTime(startTime, endTime);
  -                                             cout << "   XML parse: " << 
timeinMilliseconds << " milliseconds." << endl;
  -                                             logFile.logStatistic(
  -                                                             60,
  -                                                             
long(timeinMilliseconds),
  -                                                             
timeinMilliseconds,
  -                                                             "Parse of XML: 
");
  -
  -                                             assert(glbSourceXML != 0);
  -
  -
  -
  -                                             // The execution context uses 
the same factory support objects as
  -                                             // the processor, since those 
objects have the same lifetime as
  -                                             // other objects created as a 
result of the execution.
  -                                             
StylesheetExecutionContextDefault       psExecutionContext(
  +                                                                             
                                                csConstructionContext);
  +                             endTime = clock();
  +                             assert(glbStylesheetRoot != 0);
  +
  +                             // Calculate & report performance on stylesheet 
parse to console and log file.
  +                             timeinMilliseconds = 
calculateElapsedTime(startTime, endTime);
  +                             cout << "   XSL parse: " << timeinMilliseconds 
<< " milliseconds." << endl;
  +                             logFile.logStatistic(60,
  +                                                                     
long(timeinMilliseconds),
  +                                                                     
timeinMilliseconds,
  +                                                                     "Parse 
of XSL: ");
  +
  +                             // Parse the input XML and report how long it 
took...                             
  +                             startTime = clock();
  +                             XalanNode* const  glbSourceXML = 
parseSourceDocument(theXMLFile, 
  +                                                                             
                                                        csProcessor);
  +                             endTime = clock();
  +
  +                             // Calculate & report performance on source 
document parse to console and log file.
  +                             timeinMilliseconds = 
calculateElapsedTime(startTime, endTime);
  +                             cout << "   XML parse: " << timeinMilliseconds 
<< " milliseconds." << endl;
  +                             logFile.logStatistic(60,
  +                                                                     
long(timeinMilliseconds),
  +                                                                     
timeinMilliseconds,
  +                                                                     "Parse 
of XML: ");
  +
  +                             assert(glbSourceXML != 0);
  +
  +                             // The execution context uses the same factory 
support objects as
  +                             // the processor, since those objects have the 
same lifetime as
  +                             // other objects created as a result of the 
execution.
  +                             StylesheetExecutionContextDefault       
psExecutionContext(
                                                                        
csProcessor,
                                                                        
csXSLTProcessorEnvSupport,
                                                                        
csDOMSupport,
  @@ -404,114 +419,105 @@
   
                        
   
  -                                             // Do a total end to end 
transform with no pre parsing of either xsl or xml files.
  -                                             XSLTResultTarget                
theResultTarget(theOutputFile);
  -                                             const XSLTInputSource   
xslInputSource(c_wstr(theXSLFile));
  -                                             const XSLTInputSource   
xmlInputSource(c_wstr(theXMLFile));
  -
  -                                             const etoetran = 
eTOeTransform(xmlInputSource, 
  -                                                                             
                                xslInputSource,
  -                                                                             
                                theResultTarget,
  -                                                                             
                                csConstructionContext,
  -                                                                             
                                psExecutionContext,
  -                                                                             
                                csProcessor);
  -
  -                                             // Output single transform time 
to console and result log
  -                                             cout << "   eTOe transform: " 
<< etoetran << " milliseconds." << endl;
  -                                             logFile.logStatistic(
  -                                                             60,
  -                                                             etoetran,
  -                                                             etoetran,
  -                                                             "end To end 
transform: ");
  -
  -
  -                                             // Perform a single transform 
using compiled stylesheet and report results...
  -                                             
csProcessor.setStylesheetRoot(glbStylesheetRoot);
  -                                             const XSLTInputSource   
csSourceDocument(glbSourceXML);
  -
  -                                             startTime = clock();
  -                                             
csProcessor.process(csSourceDocument, theResultTarget, psExecutionContext);
  -                                             endTime = clock();
  -
  -                                             psExecutionContext.reset();     
// Reset the execution context...
  -                                             timeinMilliseconds = 
calculateElapsedTime(startTime, endTime);
  -
  -                                             // Output single transform time 
to console and result log
  -                                             cout << "   One transform 
w/Parsed XSL: " << timeinMilliseconds << " milliseconds." << endl;
  -
  -                                             logFile.logStatistic(
  -                                                             60,
  -                                                             
long(timeinMilliseconds),
  -                                                             
timeinMilliseconds,
  -                                                             "Single 
transform took: ");
  -
  -                                             // Perform multiple transforms 
and calculate the average time ..
  -                                             accmTime = 0;
  -                                             for(int j = 0; j < iterCount; 
++j)
  -                                             {       
  -                                                     accmTime += 
transformWParsedSource(glbSourceXML,
  +                             // Do a total end to end transform with no pre 
parsing of either xsl or xml files.
  +                             XSLTResultTarget                
theResultTarget(theOutputFile);
  +                             const XSLTInputSource   
xslInputSource(c_wstr(theXSLFile));
  +                             const XSLTInputSource   
xmlInputSource(c_wstr(theXMLFile));
  +                             const etoetran = eTOeTransform(xmlInputSource, 
  +                                                                             
                xslInputSource,
  +                                                                             
                theResultTarget,
  +                                                                             
                csConstructionContext,
  +                                                                             
                psExecutionContext,
  +                                                                             
                csProcessor);
  +
  +                             // Output single transform time to console and 
result log
  +                             cout << "   eTOe transform: " << etoetran << " 
milliseconds." << endl;
  +                             logFile.logStatistic(60,
  +                                                                     
etoetran,
  +                                                                     
etoetran,
  +                                                                     "end To 
end transform: ");
  +
  +
  +                             // Perform a single transform using compiled 
stylesheet and report results...
  +                             
csProcessor.setStylesheetRoot(glbStylesheetRoot);
  +                             const XSLTInputSource   
csSourceDocument(glbSourceXML);
  +
  +                             startTime = clock();
  +                             csProcessor.process(csSourceDocument, 
  +                                                                     
theResultTarget, 
  +                                                                     
psExecutionContext);
  +                             endTime = clock();
  +
  +                             psExecutionContext.reset();     // Reset the 
execution context...
  +                             timeinMilliseconds = 
calculateElapsedTime(startTime, endTime);
  +
  +                             // Output single transform time to console and 
result log
  +                             cout << "   One transform w/Parsed XSL: " << 
timeinMilliseconds << " milliseconds." << endl;
  +                             logFile.logStatistic(60,
  +                                                                     
long(timeinMilliseconds),
  +                                                                     
timeinMilliseconds,
  +                                                                     "Single 
transform took: ");
  +
  +                             // Perform multiple transforms and calculate 
the average time ..
  +                             accmTime = 0;
  +                             for(int j = 0; j < iterCount; ++j)
  +                             {       
  +                                     accmTime += 
transformWParsedSource(glbSourceXML,
                                                                                
                                 csProcessor,
                                                                                
                                 glbStylesheetRoot,
                                                                                
                                 theResultTarget,
                                                                                
                                 psExecutionContext);
  -                                                     
psExecutionContext.reset();
  -                                                     
  -                                             }
  -                                             csParserLiaison.reset();
  -                                             theAverage = accmTime / 
iterCount;
  -
  -                                             // Output average transform 
time to console and result log
  -                                             cout << "   Avg: " << 
theAverage << " for " << iterCount << " iter's w/Parsed XML" << endl;
  -
  -                                             char tmp[100];
  -                                             sprintf(tmp, "%s%d%s","Avg: 
transform of ", iterCount, " iter's w/Parsed XML.");
  -                                             logFile.logStatistic(
  -                                                             60, 
  -                                                             
long(theAverage), 
  -                                                             theAverage, 
  -                                                             tmp);
  +                                     psExecutionContext.reset();             
                                        
  +                             }
  +                             csParserLiaison.reset();
  +                             theAverage = accmTime / iterCount;
  +
  +                             // Output average transform time to console and 
result log
  +                             cout << "   Avg: " << theAverage << " for " << 
iterCount << " iter's w/Parsed XML" << endl;
   
  -                                             //      This is currently how 
the XalanJ 2.0 is performing transforms,
  -                                             //      i.e. with the unparsed 
XML Source.
  +                             char tmp[100];
  +                             sprintf(tmp, "%s%d%s","Avg: transform of ", 
iterCount, " iter's w/Parsed XML.");
  +                             logFile.logStatistic(60, 
  +                                                                     
long(theAverage), 
  +                                                                     
theAverage, 
  +                                                                     tmp);
  +
  +                             //      This is currently how the XalanJ 2.0 is 
performing transforms,
  +                             //      i.e. with the unparsed XML Source.
                                                
  -                                             accmTime = 0;
  -                                             for(int k = 0; k < iterCount; 
++k)
  -                                             {
  -                                                     accmTime += 
transformWUnparsedSource(theXMLFile,
  +                             accmTime = 0;
  +                             for(int k = 0; k < iterCount; ++k)
  +                             {
  +                                     accmTime += 
transformWUnparsedSource(theXMLFile,
                                                                                
                                 csProcessor,
                                                                                
                                 glbStylesheetRoot,
                                                                                
                                 theResultTarget,
                                                                                
                                 psExecutionContext);
  -                                                     
psExecutionContext.reset();             // Resets the execution context
  -                                                     
csParserLiaison.reset();                // This deletes the document
  -                                             }
  -                                             theAverage = accmTime / 
iterCount;
  -                                             cout << "   Avg: " << 
theAverage << " for " << iterCount << " iter's w/Source XML" << endl;
  -
  -                                             sprintf(tmp, "%s%d%s","Avg: 
transform of ", iterCount, " iter's w/Source XML.");
  -                                             logFile.logStatistic(
  -                                                             60, 
  -                                                             
long(theAverage), 
  -                                                             theAverage, 
  -                                                             tmp);
  -
  -                                             
logFile.logTestCaseClose(files[i], XalanDOMString("Done"));
  -                                     }
  +                                     psExecutionContext.reset();             
// Resets the execution context
  +                                     csParserLiaison.reset();                
// This deletes the document
                                }
  -                             }
  +                             theAverage = accmTime / iterCount;
  +                             cout << "   Avg: " << theAverage << " for " << 
iterCount << " iter's w/Source XML" << endl;
   
  -                             logFile.logTestFileClose("Performance", "Done");
  -                             logFile.close();
  +                             sprintf(tmp, "%s%d%s","Avg: transform of ", 
iterCount, " iter's w/Source XML.");
  +                             logFile.logStatistic(60, 
  +                                                                     
long(theAverage), 
  +                                                                     
theAverage, 
  +                                                                     tmp);
   
  -                             XMLPlatformUtils::Terminate();
  -                     }
  -                     catch(...)
  -                     {
  -                             cerr << "Exception caught!!!"
  -                                      << endl
  -                                      << endl;
  +                             logFile.logTestCaseClose(files[i], 
XalanDOMString("Done"));
  +                       }
                        }
                }
  +
  +             logFile.logTestFileClose("Performance", "Done");
  +             logFile.close();
  +
  +             XMLPlatformUtils::Terminate();
  +     }
  +     catch(...)
  +     {
  +             cerr << "Exception caught!!!" << endl  << endl;
        }
   
   
  
  
  

Reply via email to