pauldick    00/11/08 11:10:44

  Modified:    c/Tests/Performance perf.cpp
  Log:
  Removed second instance of processor,  and did alot of cleanup.
  
  Revision  Changes    Path
  1.2       +117 -100  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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- perf.cpp  2000/11/03 21:07:27     1.1
  +++ perf.cpp  2000/11/08 19:10:36     1.2
  @@ -1,3 +1,59 @@
  +/*
  + * The Apache Software License, Version 1.1
  + *
  + *
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer. 
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:  
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Xalan" and "Apache Software Foundation" must
  + *    not be used to endorse or promote products derived from this
  + *    software without prior written permission. For written 
  + *    permission, please contact [EMAIL PROTECTED]
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    nor may "Apache" appear in their name, without prior written
  + *    permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation and was
  + * originally based on software copyright (c) 1999, International
  + * Business Machines, Inc., http://www.ibm.com.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
   #include <cassert>
   #include <fstream>
   #include <iostream>
  @@ -62,7 +118,6 @@
   
   const char* const    xslStylesheets[] =
   {
  -     "v:\\xsl-test\\prod\\misc\\misc-chess",
        "v:\\xsl-test\\perf\\basic\\basic-all_well",
        "v:\\xsl-test\\perf\\basic\\basic-datetranscode",
        "v:\\xsl-test\\perf\\basic\\basic-dict2",
  @@ -81,26 +136,17 @@
   
   
   // Used to hold compiled stylesheet, and source document.
  -StylesheetRoot*              glbStylesheetRoot[sizeof(xslStylesheets) / 
sizeof(const char*)];
  +XalanNode*           glbSourceXML[sizeof(xslStylesheets) / sizeof(const 
char*)];
  +StylesheetRoot*      glbStylesheetRoot[sizeof(xslStylesheets) / sizeof(const 
char*)];
   
  -XalanNode*                   glbSourceDoc[sizeof(xslStylesheets) / 
sizeof(const char*)];
  -
  -
  -
  -void
  -outputMessage(int iter)
  +void outputMessage(int iter)
   {
  -             cout << "\n" << "Starting Iteration: " << iter << '\0';
  +     cout << "\n" << "Starting Iteration: " << iter << '\0';
   }
   
  -
  -
  -int
  -main(
  -                     int                             argc,
  -                     const char*             argv [])
  +int main( int argc,  const char* argv [])
   {
  -     assert(sizeof(glbStylesheetRoot) == sizeof(glbSourceDoc));
  +     assert(sizeof(glbStylesheetRoot) == sizeof(glbSourceXML));
   
   #if !defined(NDEBUG) && defined(_MSC_VER)
        _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | 
_CRTDBG_LEAK_CHECK_DF);
  @@ -111,20 +157,16 @@
   
        if (argc > 2)
        {
  -             cerr << "Usage: perf"
  -                      << endl
  -                      << endl;
  +             cerr << "Usage: perf" << endl  << endl;
        }
        else
        {
                int     iterCount = 1;
  -
                if (argc == 2)
                {
                        iterCount = atoi(argv[1]);
                }
   
  -
                try
                {
                        // Call the static initializers...
  @@ -132,8 +174,12 @@
   
                        {
                                XSLTInit        theInit;
  +
  +                             const XalanDOMString  XSLSuffix(".xsl");
  +                             const XalanDOMString  XMLSuffix(".xml");
  +                             const XalanDOMString  outputSuffix(".out");
   
  -                             // Create the necessary stuff to compile the 
stylesheet.
  +                             // Create the necessary support objects to 
instantiate a processor.
                                XercesDOMSupport                            
csDOMSupport;
                                XercesParserLiaison                             
csParserLiaison(csDOMSupport);
                                XPathSupportDefault                             
csXPathSupport(csDOMSupport);
  @@ -141,116 +187,87 @@
                                XObjectFactoryDefault                   
csXObjectFactory;
                                XPathFactoryDefault                             
csXPathFactory;
   
  -                             // Create a processor to compile the 
stylesheet...
  +                             // Create a processor for stylesheet 
compilation and connect to 
  +                             // ProcessorEnvSupport object
                                XSLTEngineImpl  csProcessor(
                                                csParserLiaison,
                                                csXPathSupport,
                                                csXSLTProcessorEnvSupport,
                                                csDOMSupport,
  -                                             csXObjectFactory,
  +                                             csXObjectFactory,   
                                                csXPathFactory);
  -
  -                             // Connect the processor to the support 
object...
                                
csXSLTProcessorEnvSupport.setProcessor(&csProcessor);
   
  -                             // Create separate factory support objects so 
the stylesheet's
  -                             // factory-created XObject and XPath instances 
are independent 
  -                             // from processor's.
  -                             XObjectFactoryDefault   
csStylesheetXObjectFactory;
  -                             XPathFactoryDefault             
csStylesheetXPathFactory;
  +                             // 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,
  -                                                                             
                                csStylesheetXPathFactory);
  +                                                                             
                                ssXPathFactory);
   
  -                             const XalanDOMString  theXSLSuffix(".xsl");
  -                             const XalanDOMString  theXMLSuffix(".xml");
  -                             const XalanDOMString  theoutputSuffix(".out");
  -
                                for(int i = 0; xslStylesheets[i] != 0; i++)
                                {
  -                                     const XalanDOMString  
theXSLFilename(XalanDOMString(xslStylesheets[i]) + theXSLSuffix);
  -                                     const XalanDOMString  
theXMLFilename(XalanDOMString(xslStylesheets[i]) + theXMLSuffix);
  +                                     const XalanDOMString  
theXSLfile(XalanDOMString(xslStylesheets[i]) + XSLSuffix);
  +                                     const XalanDOMString  
theXMLfile(XalanDOMString(xslStylesheets[i]) + XMLSuffix);
   
                                        cout << "Now compiling Stylesheet: " << 
xslStylesheets[i] << endl;
   
                                        //Generate the XML and XSL input 
objects.
  -                                     XSLTInputSource         
csStylesheetSourceXSL(c_wstr(theXSLFilename));
  -                                     XSLTInputSource         
csDocumentSource(c_wstr(theXMLFilename));
  +                                     XSLTInputSource         
csStylesheetSourceXSL(c_wstr(theXSLfile));
  +                                     XSLTInputSource         
csSourceXML(c_wstr(theXMLfile));
   
  -                                     // Ask the processor to create a 
StylesheetRoot for the specified
  -                                     // input XSL.  This is the compiled 
stylesheet.  We don't have to
  -                                     // delete it, since it is owned by the 
StylesheetConstructionContext
  -                                     // instance.
  +                                     // Ask the processor to create a 
compiled stylesheet (StylesheetRoot) for the 
  +                                     // specified input XSL. We don't have 
to delete it, since it is owned by the 
  +                                     // StylesheetConstructionContext 
instance.
                                        glbStylesheetRoot[i] = 
csProcessor.processStylesheet(csStylesheetSourceXSL,
                                                                                
                                   csConstructionContext);
                                        assert(glbStylesheetRoot[i] != 0);
   
                                        // Have the processor create a compiled 
SourceDocument for the specified
                                        // input XML. 
  -                                     glbSourceDoc[i] = 
csProcessor.getSourceTreeFromInput(csDocumentSource);
  -                                     assert(glbSourceDoc[i] != 0);
  +                                     glbSourceXML[i] = 
csProcessor.getSourceTreeFromInput(csSourceXML);
  +                                     assert(glbSourceXML[i] != 0);
                                }
   
  +                             for(int ii = 0; xslStylesheets[ii] != 0; ii++)
  +                             {
  +                                     cout << endl << "Now running test: " << 
xslStylesheets[ii] << endl;
   
  -                                     for(int ii = 0; xslStylesheets[ii] != 
0; ii++)
  -                                     {
  -                                             cout << endl << "Now running 
test: " << xslStylesheets[ii] << endl;
  -
  -                                             // Create the necessary stuff 
to run the processor.
  -                                             XercesDOMSupport                
                psDOMSupport;
  -                                             XercesParserLiaison             
                psParserLiaison(psDOMSupport);
  -                                             XPathSupportDefault             
                psXPathSupport(psDOMSupport);
  -                                             XSLTProcessorEnvSupportDefault  
psXSLTProcessorEnvSupport;
  -                                             XObjectFactoryDefault           
        psXObjectFactory;
  -                                             XPathFactoryDefault             
                psXPathFactory;
  -
  -                                             // Create a processor to 
perform the transform.
  -                                             XSLTEngineImpl  psProcessor(
  -                                                     psParserLiaison,
  -                                                     psXPathSupport,
  -                                                     
psXSLTProcessorEnvSupport,
  -                                                     psDOMSupport,
  -                                                     psXObjectFactory,
  -                                                     psXPathFactory);
  -
  -                                             // Connect the processor to the 
support object...
  -                                             
psXSLTProcessorEnvSupport.setProcessor(&psProcessor);
  -
  -                                             // 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(
  -                                                             psProcessor,
  -                                                             
psXSLTProcessorEnvSupport,
  -                                                             psXPathSupport,
  -                                                             
psXObjectFactory);
  -
  -                                             const XalanDOMString  
outputFileName(XalanDOMString(xslStylesheets[ii]) + theoutputSuffix);
  -
  -                                             //Generate the XML input and 
output objects.
  -                                             XSLTInputSource         
csDocumentSource(glbSourceDoc[ii]);
  -                                             XSLTResultTarget        
theResultTarget(outputFileName);
  -
  -                                             // Set the stylesheet to be the 
compiled stylesheet. Then do the transform.
  -                                             const double startTime = 
clock();
  -                                             cout << "Clock before 
transforms: " << startTime << endl;
  -                                             for(int j = 0; j < iterCount; 
++j)
  -                                             {       
  -                                                     
psProcessor.setStylesheetRoot(glbStylesheetRoot[ii]);
  -                                                     
psProcessor.process(csDocumentSource, theResultTarget,psExecutionContext);
  -                                                     
psExecutionContext.reset();
  -                                             }
  -                                             const double endTime = clock();
  -                                             cout << "Clock after 
transforms: " << endTime << endl;
  -                                             cout << "Total clock ticks: " 
<< endTime - startTime << endl;
  -                                             const double    millis = 
((endTime - startTime) / CLOCKS_PER_SEC) * 1000.0;
  -                                             cout << "Milliseconds: " << 
millis << endl;
  -                                             cout << "Averaged: " << millis 
/ iterCount << " per iteration" << endl;
  +                                     // 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,
  +                                                     csXPathSupport,
  +                                                     csXObjectFactory);
  +
  +                                     const XalanDOMString  
outputfile(XalanDOMString(xslStylesheets[ii]) + outputSuffix);
  +
  +                                     //Generate the XML input and output 
objects.
  +                                     XSLTInputSource         
csSourceXML(glbSourceXML[ii]);
  +                                     XSLTResultTarget        
theResultTarget(outputfile);
  +
  +                                     // Set the stylesheet to be the 
compiled stylesheet. Then do the transform.
  +                                     const double startTime = clock();
  +                                     cout << "Clock before transforms: " << 
startTime << endl;
  +                                     for(int j = 0; j < iterCount; ++j)
  +                                     {       
  +                                             
csProcessor.setStylesheetRoot(glbStylesheetRoot[ii]);
  +                                             
csProcessor.process(csSourceXML, theResultTarget,psExecutionContext);
  +                                             psExecutionContext.reset();
                                        }
  +                                     const double endTime = clock();
  +                                     cout << "Clock after transforms: " << 
endTime << endl;
  +                                     cout << "Total clock ticks: " << 
endTime - startTime << endl;
  +                                     const double    millis = ((endTime - 
startTime) / CLOCKS_PER_SEC) * 1000.0;
  +                                     cout << "Milliseconds: " << millis << 
endl;
  +                                     cout << "Averaged: " << millis / 
iterCount << " per iteration" << endl;
  +                             }
                                
                        }
   
  
  
  

Reply via email to