From 5e527213a2430bb3018e5eebd909aef294edf9b5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 18 Dec 2020 18:48:46 +0300 Subject: Switch to build2 --- xsd-examples/cxx/tree/performance/.gitignore | 5 + xsd-examples/cxx/tree/performance/README | 62 ++++++++ xsd-examples/cxx/tree/performance/buildfile | 36 +++++ xsd-examples/cxx/tree/performance/driver.cxx | 90 +++++++++++ xsd-examples/cxx/tree/performance/gen.cxx | 76 +++++++++ xsd-examples/cxx/tree/performance/gen.testscript | 9 ++ xsd-examples/cxx/tree/performance/parsing.cxx | 172 +++++++++++++++++++++ .../cxx/tree/performance/serialization.cxx | 132 ++++++++++++++++ xsd-examples/cxx/tree/performance/test-50k.xml | 1 + xsd-examples/cxx/tree/performance/test.xsd | 49 ++++++ xsd-examples/cxx/tree/performance/time.cxx | 46 ++++++ xsd-examples/cxx/tree/performance/time.hxx | 110 +++++++++++++ 12 files changed, 788 insertions(+) create mode 100644 xsd-examples/cxx/tree/performance/.gitignore create mode 100644 xsd-examples/cxx/tree/performance/README create mode 100644 xsd-examples/cxx/tree/performance/buildfile create mode 100644 xsd-examples/cxx/tree/performance/driver.cxx create mode 100644 xsd-examples/cxx/tree/performance/gen.cxx create mode 100644 xsd-examples/cxx/tree/performance/gen.testscript create mode 100644 xsd-examples/cxx/tree/performance/parsing.cxx create mode 100644 xsd-examples/cxx/tree/performance/serialization.cxx create mode 100644 xsd-examples/cxx/tree/performance/test-50k.xml create mode 100644 xsd-examples/cxx/tree/performance/test.xsd create mode 100644 xsd-examples/cxx/tree/performance/time.cxx create mode 100644 xsd-examples/cxx/tree/performance/time.hxx (limited to 'xsd-examples/cxx/tree/performance') diff --git a/xsd-examples/cxx/tree/performance/.gitignore b/xsd-examples/cxx/tree/performance/.gitignore new file mode 100644 index 0000000..b143f97 --- /dev/null +++ b/xsd-examples/cxx/tree/performance/.gitignore @@ -0,0 +1,5 @@ +gen + +# Testscript output directory (can be symlink). +# +test-gen diff --git a/xsd-examples/cxx/tree/performance/README b/xsd-examples/cxx/tree/performance/README new file mode 100644 index 0000000..0206387 --- /dev/null +++ b/xsd-examples/cxx/tree/performance/README @@ -0,0 +1,62 @@ +This example measures the performance of parsing and serialization in +the C++/Tree mapping. It also shows how to structure your code to +achieve the maximum performance for these two operations. + +The example consists of the following files: + +test.xsd + XML Schema which describes the test vocabulary. + +test-50k.xml + Test XML document. + +gen.cxx + Program to generate a test document of desired size. + +time.hxx +time.cxx + Class definition that represents time. + +test.hxx +test.ixx +test.cxx + C++ types that represent the given vocabulary, a set of parsing + functions that convert XML documents to a tree-like in-memory object + model, and a set of serialization functions that convert the object + model back to XML. These are generated by the XSD compiler from + test.xsd. + +parsing.cxx + Parsing performance test. It first reads the entire document into + a memory buffer. It then creates a DOM parser and pre-parses and + caches the schema if validation is enabled. Finally, it runs the + performance measurement loop which on each iteration parses the + XML document from the in-memory buffer into DOM and then DOM to + the object model. + +serialization.cxx + Serialization performance test. It first parses the XML document + into the object model. It then creates a memory buffer into which + the document is serialized and a DOM serializer. Finally, it runs + the performance measurement loop which on each iteration serializes + the object model to DOM and DOM to XML. + +driver.cxx + Driver for the example. It first parses the command line arguments. + It then initializes the Xerces-C++ runtime and calls the parsing + and serialization tests described above. + +To run the example on a test XML document simply execute: + +$ ./driver test-50k.xml + +The -v option can be used to turn on validation in the underlying XML +parser (off by default). The -i option can be used to specify the +number of parsing and serialization iterations (1000 by default). For +example: + +$ ./driver -v -i 100 test-50k.xml + +To generate the test document execute, for example: + +$ ./gen 633 test-100k.xml diff --git a/xsd-examples/cxx/tree/performance/buildfile b/xsd-examples/cxx/tree/performance/buildfile new file mode 100644 index 0000000..e9faeef --- /dev/null +++ b/xsd-examples/cxx/tree/performance/buildfile @@ -0,0 +1,36 @@ +# file : cxx/tree/performance/buildfile +# license : not copyrighted - public domain + +import libs = libxsd%lib{xsd} +import libs += libxerces-c%lib{xerces-c} + +./: doc{README} + +# exe{driver} +# +./: exe{driver}: {hxx cxx}{* -gen -test} {hxx ixx cxx}{test} $libs + +exe{driver}: xml{test-50k}: test.input = true + +<{hxx ixx cxx}{test}>: xsd{test} $xsd +{{ + diag xsd ($<[0]) # @@ TMP + + $xsd cxx-tree --std c++11 \ + --generate-inline \ + --generate-serialization \ + --output-dir $out_base \ + $path($<[0]) +}} + +# exe{gen} +# +./: exe{gen}: cxx{gen} testscript{gen} + +# Build options. +# +cxx.poptions =+ "-I$out_base" "-I$src_base" + +# Define XSD_CXX11 since we include libxsd headers directly. +# +cxx.poptions += -DXSD_CXX11 diff --git a/xsd-examples/cxx/tree/performance/driver.cxx b/xsd-examples/cxx/tree/performance/driver.cxx new file mode 100644 index 0000000..b156f84 --- /dev/null +++ b/xsd-examples/cxx/tree/performance/driver.cxx @@ -0,0 +1,90 @@ +// file : cxx/tree/performance/driver.cxx +// copyright : not copyrighted - public domain + +#include +#include +#include + +#include + +using namespace std; + +// See parsing.cxx +// +bool +parsing (const char* file, unsigned long iter, bool validate); + +// See serialization.cxx +// +bool +serialization (const char* file, unsigned long iter); + +int +main (int argc, char* argv[]) +{ + if (argc < 2) + { + cerr << "usage: " << argv[0] << " [-v] [-i ] test.xml" << endl + << "\t -v turn on validation (default is off)" << endl + << "\t -i number of iterations to perform (default is 1000)" << endl; + return 1; + } + + bool validate (false); + unsigned long iter (1000); + const char* file (0); + + // Parse command line arguments. + // + for (int i (1); i < argc; ++i) + { + std::string arg (argv[i]); + + if (arg == "-v") + { + validate = true; + } + else if (arg == "-i") + { + if (++i == argc) + { + cerr << "argument expected for the -i option" << endl; + return 1; + } + + iter = 0; + istringstream is (argv[i]); + is >> iter; + + if (iter == 0) + { + cerr << "invalid argument for the -i option" << endl; + return 1; + } + } + else + { + file = argv[i]; + break; + } + } + + if (file == 0) + { + cerr << "no input file specified" << endl; + return 1; + } + + int r (0); + + xercesc::XMLPlatformUtils::Initialize (); + + // Call parsing and serialization tests. + // + if (!parsing (file, iter, validate) || !serialization (file, iter)) + r = 1; + + xercesc::XMLPlatformUtils::Terminate (); + + return r; +} diff --git a/xsd-examples/cxx/tree/performance/gen.cxx b/xsd-examples/cxx/tree/performance/gen.cxx new file mode 100644 index 0000000..b6392c0 --- /dev/null +++ b/xsd-examples/cxx/tree/performance/gen.cxx @@ -0,0 +1,76 @@ +#include +#include +#include + +using namespace std; + +static const char* enums[] = +{ + "romance", + "fiction", + "horror", + "history", + "philosophy" +}; + +int +main (int argc, char* argv[]) +{ + if (argc != 3) + { + cerr << "usage: " << argv[0] << " " << endl; + return 1; + } + + unsigned long n (0); + istringstream is (argv[1]); + is >> n; + + if (n == 0) + { + cerr << "record count argument should be a positive number" << endl; + return 1; + } + + ofstream ofs (argv[2]); + + if (!ofs.is_open ()) + { + cerr << "unable to open '" << argv[2] << "' in write mode" << endl; + return 1; + } + + ofs << ""; + + unsigned short ch (1), en (0); + + for (unsigned long i (0); i < n; ++i) + { + ofs << "" + << "42" + << "42345.4232" + << "name123_45"; + + if (i % 2 == 1) + ofs << "one two three"; + + ofs << "" << ch << " choice" + << "" << enums[en] << "" + << ""; + + if (++ch > 4) + ch = 1; + + if (++en > 4) + en = 0; + } + + ofs << ""; +} diff --git a/xsd-examples/cxx/tree/performance/gen.testscript b/xsd-examples/cxx/tree/performance/gen.testscript new file mode 100644 index 0000000..deefc05 --- /dev/null +++ b/xsd-examples/cxx/tree/performance/gen.testscript @@ -0,0 +1,9 @@ +# file : cxx/tree/performance/gen.testscript +# license : not copyrighted - public domain + +: 50k +: +{ + $* 317 test-50k.xml &test-50k.xml; + cat test-50k.xml >>>$src_base/test-50k.xml +} diff --git a/xsd-examples/cxx/tree/performance/parsing.cxx b/xsd-examples/cxx/tree/performance/parsing.cxx new file mode 100644 index 0000000..c41b57d --- /dev/null +++ b/xsd-examples/cxx/tree/performance/parsing.cxx @@ -0,0 +1,172 @@ +// file : cxx/tree/performance/parsing.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include // std::size_t +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include + +#include + +#include +#include + +#include "time.hxx" +#include "test.hxx" + +using namespace std; + +bool +parsing (const char* file, unsigned long iter, bool validate) +{ + try + { + cerr << "parsing:" << endl; + + ifstream ifs; + ifs.exceptions (ios_base::failbit); + ifs.open (file, ios::in | ios::ate); + + size_t size (ifs.tellg ()); + ifs.seekg (0, ios::beg); + + char* buf = new char[size]; + ifs.read (buf, size); + ifs.close (); + + cerr << " document size: " << size << " bytes" << endl + << " iterations: " << iter << endl; + + // Create XML parser that we are going to use in all iterations. + // + using namespace xercesc; + + const XMLCh ls_id[] = + {xercesc::chLatin_L, xercesc::chLatin_S, xercesc::chNull}; + + DOMImplementation* impl ( + DOMImplementationRegistry::getDOMImplementation (ls_id)); + + // Use the error handler implementation provided by the XSD runtime. + // + xsd::cxx::tree::error_handler eh; + xsd::cxx::xml::dom::bits::error_handler_proxy ehp (eh); + + xml_schema::dom::unique_ptr parser ( + impl->createLSParser (DOMImplementationLS::MODE_SYNCHRONOUS, 0)); + + DOMConfiguration* conf (parser->getDomConfig ()); + + conf->setParameter (XMLUni::fgDOMComments, false); + conf->setParameter (XMLUni::fgDOMDatatypeNormalization, true); + conf->setParameter (XMLUni::fgDOMEntities, false); + conf->setParameter (XMLUni::fgDOMNamespaces, true); + conf->setParameter (XMLUni::fgDOMElementContentWhitespace, false); + + // Set error handler. + // + conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp); + + if (validate) + { + conf->setParameter (XMLUni::fgDOMValidate, true); + conf->setParameter (XMLUni::fgXercesSchema, true); + conf->setParameter (XMLUni::fgXercesSchemaFullChecking, false); + + // Xerces-C++ 3.1.0 is the first version with working multi import + // support. + // +#if _XERCES_VERSION >= 30100 + conf->setParameter (XMLUni::fgXercesHandleMultipleImports, true); +#endif + + // If we are validating, pre-load and cache the schema. + // + if (!parser->loadGrammar ("test.xsd", Grammar::SchemaGrammarType, true)) + { + // In Xerces-C++ grammar loading failure results in just a warning. + // Make it a fatal error. + // + eh.handle ("test.xsd", 0, 0, + xsd::cxx::tree::error_handler::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed (); + conf->setParameter (XMLUni::fgXercesUseCachedGrammarInParse, true); + conf->setParameter (XMLUni::fgXercesLoadSchema, false); + } + else + { + conf->setParameter (XMLUni::fgDOMValidate, false); + conf->setParameter (XMLUni::fgXercesSchema, false); + conf->setParameter (XMLUni::fgXercesSchemaFullChecking, false); + } + + conf->setParameter (XMLUni::fgXercesUserAdoptsDOMDocument, true); + + // Create memory buffer input source. + // + MemBufInputSource is ( + reinterpret_cast (buf), size, file, false); + is.setCopyBufToStream (false); + Wrapper4InputSource wis (&is, false); + + // Parsing loop. + // + os::time start; + + for (unsigned long i (0); i < iter; ++i) + { + // First parse XML to DOM reusing the parser we created above. + // + xml_schema::dom::unique_ptr doc (parser->parse (&wis)); + eh.throw_if_failed (); + + // Then parse DOM to the object model. + // + unique_ptr r (test::root_ (*doc)); + } + + os::time end; + os::time time (end - start); + + delete[] buf; + + cerr << " time: " << time << " sec" << endl; + + double ms (time.sec () * 1000000ULL + time.nsec () / 1000ULL); + + // Calculate throughput in documents/sec. + // + double tpd ((iter / ms) * 1000000); + cerr << " throughput: " << tpd << " documents/sec" << endl; + + // Calculate throughput in MBytes/sec. + // + double tpb (((size * iter) / ms) * 1000000/(1024*1024)); + cerr << " throughput: " << tpb << " MBytes/sec" << endl; + } + catch (const xml_schema::exception& e) + { + cerr << e << endl; + return false; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return false; + } + + return true; +} diff --git a/xsd-examples/cxx/tree/performance/serialization.cxx b/xsd-examples/cxx/tree/performance/serialization.cxx new file mode 100644 index 0000000..e81fcbd --- /dev/null +++ b/xsd-examples/cxx/tree/performance/serialization.cxx @@ -0,0 +1,132 @@ +// file : cxx/tree/performance/serialization.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include // std::size_t +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include + +#include "time.hxx" +#include "test.hxx" + +using namespace std; + +bool +serialization (const char* file, unsigned long iter) +{ + try + { + using namespace xercesc; + + cerr << "serialization:" << endl; + + // Get the object model using the standard parsing function. + // + unique_ptr r ( + test::root_ (file, + xml_schema::flags::dont_initialize | + xml_schema::flags::dont_validate)); + + // Serialize it to the in-memory buffer. This makes sure the buffer + // pre-allocates enough memory. + // + xml_schema::namespace_infomap map; + map["t"].name = "test"; + map["t"].schema = "test.xsd"; + + MemBufFormatTarget ft (10240); + test::root_ (ft, *r, map, "UTF-8", + xml_schema::flags::dont_initialize | + xml_schema::flags::dont_pretty_print | + xml_schema::flags::no_xml_declaration); + + size_t size (ft.getLen ()); + cerr << " document size: " << size << " bytes" << endl + << " iterations: " << iter << endl; + + // Create XML serializer that we are going to use in all iterations. + // + const XMLCh ls_id[] = + {xercesc::chLatin_L, xercesc::chLatin_S, xercesc::chNull}; + + DOMImplementation* impl ( + DOMImplementationRegistry::getDOMImplementation (ls_id)); + + // Use the error handler implementation provided by the XSD runtime. + // + xsd::cxx::tree::error_handler eh; + xsd::cxx::xml::dom::bits::error_handler_proxy ehp (eh); + + xml_schema::dom::unique_ptr writer ( + impl->createLSSerializer ()); + + DOMConfiguration* conf (writer->getDomConfig ()); + + conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp); + conf->setParameter (XMLUni::fgDOMXMLDeclaration, false); + + xml_schema::dom::unique_ptr out (impl->createLSOutput ()); + + out->setByteStream (&ft); + + // Serialization loop. + // + os::time start; + + for (unsigned long i (0); i < iter; ++i) + { + // First serialize the object model to DOM. + // + xml_schema::dom::unique_ptr doc (test::root_ (*r, map)); + + ft.reset (); + + // Then serialize DOM to XML reusing the serializer we created above. + // + writer->write (doc.get (), out.get ()); + eh.throw_if_failed (); + } + + os::time end; + os::time time (end - start); + + cerr << " time: " << time << " sec" << endl; + + double ms (time.sec () * 1000000ULL + time.nsec () / 1000ULL); + + // Calculate throughput in documents/sec. + // + double tpd ((iter / ms) * 1000000); + cerr << " throughput: " << tpd << " documents/sec" << endl; + + // Calculate throughput in MBytes/sec. + // + double tpb (((size * iter) / ms) * 1000000/(1024*1024)); + cerr << " throughput: " << tpb << " MBytes/sec" << endl; + } + catch (const xml_schema::exception& e) + { + cerr << e << endl; + return false; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return false; + } + + return true; +} diff --git a/xsd-examples/cxx/tree/performance/test-50k.xml b/xsd-examples/cxx/tree/performance/test-50k.xml new file mode 100644 index 0000000..42e22f3 --- /dev/null +++ b/xsd-examples/cxx/tree/performance/test-50k.xml @@ -0,0 +1 @@ +4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction4242345.4232name123_45one two three2 choicehorror4242345.4232name123_453 choicehistory4242345.4232name123_45one two three4 choicephilosophy4242345.4232name123_451 choiceromance4242345.4232name123_45one two three2 choicefiction4242345.4232name123_453 choicehorror4242345.4232name123_45one two three4 choicehistory4242345.4232name123_451 choicephilosophy4242345.4232name123_45one two three2 choiceromance4242345.4232name123_453 choicefiction4242345.4232name123_45one two three4 choicehorror4242345.4232name123_451 choicehistory4242345.4232name123_45one two three2 choicephilosophy4242345.4232name123_453 choiceromance4242345.4232name123_45one two three4 choicefiction4242345.4232name123_451 choicehorror4242345.4232name123_45one two three2 choicehistory4242345.4232name123_453 choicephilosophy4242345.4232name123_45one two three4 choiceromance4242345.4232name123_451 choicefiction \ No newline at end of file diff --git a/xsd-examples/cxx/tree/performance/test.xsd b/xsd-examples/cxx/tree/performance/test.xsd new file mode 100644 index 0000000..98ee921 --- /dev/null +++ b/xsd-examples/cxx/tree/performance/test.xsd @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xsd-examples/cxx/tree/performance/time.cxx b/xsd-examples/cxx/tree/performance/time.cxx new file mode 100644 index 0000000..48385a1 --- /dev/null +++ b/xsd-examples/cxx/tree/performance/time.cxx @@ -0,0 +1,46 @@ +// file : cxx/tree/performance/time.cxx +// copyright : not copyrighted - public domain + +#include "time.hxx" + +#if defined (WIN32) || defined (__WIN32__) +# define WIN32_LEAN_AND_MEAN +# include // GetSystemTimeAsFileTime +#else +# include // gettimeofday +# include // timeval +#endif + +#include // std::ostream +#include // std::setfill, std::setw + +namespace os +{ + time:: + time () + { +#if defined (WIN32) || defined (__WIN32__) + FILETIME ft; + GetSystemTimeAsFileTime (&ft); + unsigned long long v ( + ((unsigned long long) (ft.dwHighDateTime) << 32) + ft.dwLowDateTime); + + sec_ = static_cast (v / 10000000ULL); + nsec_ = static_cast ((v % 10000000ULL) * 100); +#else + timeval tv; + if (gettimeofday(&tv, 0) != 0) + throw failed (); + + sec_ = static_cast (tv.tv_sec); + nsec_ = static_cast (tv.tv_usec * 1000); +#endif + } + + std::ostream& + operator<< (std::ostream& o, time const& t) + { + return o << t.sec () << '.' + << std::setfill ('0') << std::setw (9) << t.nsec (); + } +} diff --git a/xsd-examples/cxx/tree/performance/time.hxx b/xsd-examples/cxx/tree/performance/time.hxx new file mode 100644 index 0000000..b05414b --- /dev/null +++ b/xsd-examples/cxx/tree/performance/time.hxx @@ -0,0 +1,110 @@ +// file : cxx/tree/performance/time.hxx +// copyright : not copyrighted - public domain + +#ifndef TIME_HXX +#define TIME_HXX + +#include // std::ostream& + +namespace os +{ + class time + { + public: + class failed {}; + + // Create a time object representing the current time. + // + time (); + + time (unsigned long long nsec) + { + sec_ = static_cast (nsec / 1000000000ULL); + nsec_ = static_cast (nsec % 1000000000ULL); + } + + time (unsigned long sec, unsigned long nsec) + { + sec_ = sec; + nsec_ = nsec; + } + + public: + unsigned long + sec () const + { + return sec_; + } + + unsigned long + nsec () const + { + return nsec_; + } + + public: + class overflow {}; + class underflow {}; + + time + operator+= (time const& b) + { + unsigned long long tmp = 0ULL + nsec_ + b.nsec_; + + sec_ += static_cast (b.sec_ + tmp / 1000000000ULL); + nsec_ = static_cast (tmp % 1000000000ULL); + + return *this; + } + + time + operator-= (time const& b) + { + if (*this < b) + throw underflow (); + + sec_ -= b.sec_; + + if (nsec_ < b.nsec_) + { + --sec_; + nsec_ += 1000000000ULL - b.nsec_; + } + else + nsec_ -= b.nsec_; + + return *this; + } + + friend time + operator+ (time const& a, time const& b) + { + time r (a); + r += b; + return r; + } + + friend time + operator- (time const& a, time const& b) + { + time r (a); + r -= b; + return r; + } + + friend bool + operator < (time const& a, time const& b) + { + return (a.sec_ < b.sec_) || (a.sec_ == b.sec_ && a.nsec_ < b.nsec_); + } + + private: + unsigned long sec_; + unsigned long nsec_; + }; + + std::ostream& + operator<< (std::ostream&, time const&); +} + +#endif // TIME_HXX -- cgit v1.1