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/parser/performance/.gitignore | 7 + xsd-examples/cxx/parser/performance/README | 46 +++ xsd-examples/cxx/parser/performance/buildfile | 57 ++++ xsd-examples/cxx/parser/performance/driver.cxx | 346 +++++++++++++++++++++ xsd-examples/cxx/parser/performance/gen.cxx | 79 +++++ xsd-examples/cxx/parser/performance/gen.testscript | 9 + xsd-examples/cxx/parser/performance/test-50k.xml | 1 + xsd-examples/cxx/parser/performance/test.xsd | 49 +++ xsd-examples/cxx/parser/performance/time.cxx | 46 +++ xsd-examples/cxx/parser/performance/time.hxx | 110 +++++++ 10 files changed, 750 insertions(+) create mode 100644 xsd-examples/cxx/parser/performance/.gitignore create mode 100644 xsd-examples/cxx/parser/performance/README create mode 100644 xsd-examples/cxx/parser/performance/buildfile create mode 100644 xsd-examples/cxx/parser/performance/driver.cxx create mode 100644 xsd-examples/cxx/parser/performance/gen.cxx create mode 100644 xsd-examples/cxx/parser/performance/gen.testscript create mode 100644 xsd-examples/cxx/parser/performance/test-50k.xml create mode 100644 xsd-examples/cxx/parser/performance/test.xsd create mode 100644 xsd-examples/cxx/parser/performance/time.cxx create mode 100644 xsd-examples/cxx/parser/performance/time.hxx (limited to 'xsd-examples/cxx/parser/performance') diff --git a/xsd-examples/cxx/parser/performance/.gitignore b/xsd-examples/cxx/parser/performance/.gitignore new file mode 100644 index 0000000..19c9761 --- /dev/null +++ b/xsd-examples/cxx/parser/performance/.gitignore @@ -0,0 +1,7 @@ +driver-expat +driver-xerces +gen + +# Testscript output directory (can be symlink). +# +test-gen diff --git a/xsd-examples/cxx/parser/performance/README b/xsd-examples/cxx/parser/performance/README new file mode 100644 index 0000000..46137d0 --- /dev/null +++ b/xsd-examples/cxx/parser/performance/README @@ -0,0 +1,46 @@ +This example measures the performance of XML parsing in the C++/Parser +mapping. It also shows how to structure your code to achieve the maximum +performance for this operation. + +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-pskel.hxx +test-pskel.ixx +test-pskel.cxx + Parser skeletons generated by the XSD compiler from test.xsd. + +driver.cxx + Driver for the example. It first parses the command line arguments + and reads the entire document into a memory buffer. It then creates + a SAX parser and pre-parses and caches the schema if validation is + enabled (Xerces-C++ only). Finally, it runs the performance + measurement loop which on each iteration parses the XML document + from the in-memory buffer. + +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 (only makes sense for Xerces-C++, off by default). The -i option +can be used to specify the number of parsing 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/parser/performance/buildfile b/xsd-examples/cxx/parser/performance/buildfile new file mode 100644 index 0000000..10111d6 --- /dev/null +++ b/xsd-examples/cxx/parser/performance/buildfile @@ -0,0 +1,57 @@ +# file : cxx/parser/performance/buildfile +# license : not copyrighted - public domain + +import libs = libxsd%lib{xsd} + +import libxerces = libxerces-c%lib{xerces-c} +import libexpat = libexpat%lib{expat} + +./: doc{README} + +# exe{driver-{xerces,expat}} +# +for p: 'xerces' 'expat' +{ + # Make sure that obje{time} doesn't depend on the parser library that varies + # for different exe{driver-*} targets. Think of -I... options passed to the + # compiler while compiling time.cxx, which would vary depending on exe + # target time.cxx is a prerequisite of. + # + ./: exe{driver-$p}: obje{driver-$p time} \ + {hxx ixx cxx}{test-$p-pskel} \ + $libs $(lib$p) + + exe{driver-$p}: xml{test-50k}: test.input = true + + obje{driver-$p}: cxx{driver} $libs $(lib$p) + + <{hxx ixx cxx}{test-$p-pskel}>: xsd{test} $xsd + { + # Note: we can't use $p in the buildscript since it will be substituted by + # the latest $p value. + # + parser = $p + } + {{ + diag xsd ($<[0]) # @@ TMP + + $xsd cxx-parser --std c++11 \ + --generate-inline \ + --skel-file-suffix -$parser-pskel \ + --xml-parser $parser \ + --output-dir $out_base \ + $path($<[0]) + }} +} + +obje{time}: {hxx cxx}{time} + +# exe{gen} +# +./: exe{gen}: cxx{gen} testscript{gen} + +# Build options. +# +cxx.poptions =+ "-I$out_base" "-I$src_base" + +obje{driver-xerces}: cxx.poptions += -DXERCES_PARSER diff --git a/xsd-examples/cxx/parser/performance/driver.cxx b/xsd-examples/cxx/parser/performance/driver.cxx new file mode 100644 index 0000000..4ac0265 --- /dev/null +++ b/xsd-examples/cxx/parser/performance/driver.cxx @@ -0,0 +1,346 @@ +// file : cxx/parser/performance/driver.cxx +// copyright : not copyrighted - public domain + +#include +#include // std::unique_ptr +#include // std::size_t +#include +#include +#include + +#include "time.hxx" + +#ifdef XERCES_PARSER +# include "test-xerces-pskel.hxx" + +# include +# include +# include +# include +# include +# include + +# include +# include +#else +# include "test-expat-pskel.hxx" +#endif + +// No-op parser implementation. +// +namespace test +{ + struct enum_pimpl: enum_pskel, xml_schema::string_pimpl + { + virtual void + post_enum () + { + } + }; + + struct record_pimpl: record_pskel + { + virtual void + int_ (unsigned int) + { + } + + virtual void + double_ (double) + { + } + + virtual void + name (const std::string&) + { + } + + virtual void + string (const std::string&) + { + } + + virtual void + choice1 (const std::string&) + { + } + + virtual void + choice2 (const std::string&) + { + } + + virtual void + choice3 (const std::string&) + { + } + + virtual void + choice4 (const std::string&) + { + } + + virtual void + apple (bool) + { + } + + virtual void + orange (unsigned long long) + { + } + }; + + struct root_pimpl: root_pskel + { + }; +} + +using namespace std; + +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) + { + 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; + } + + try + { + // Instantiate and connect parsers. + // + xml_schema::unsigned_int_pimpl unsigned_int_p; + xml_schema::double_pimpl double_p; + xml_schema::ncname_pimpl ncname_p; + xml_schema::string_pimpl string_p; + xml_schema::boolean_pimpl boolean_p; + xml_schema::unsigned_long_pimpl unsigned_long_p; + + test::enum_pimpl enum_p; + test::record_pimpl record_p; + test::root_pimpl root_p; + + record_p.parsers (unsigned_int_p, + double_p, + ncname_p, + string_p, + string_p, + string_p, + string_p, + string_p, + enum_p, + boolean_p, + unsigned_long_p); + + root_p.parsers (record_p); + + // Read the fine into in-memory buffer. + // + 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; + + os::time time (0); + xml_schema::document doc (root_p, "test", "root"); + +#ifdef _XERCES_VERSION + + // Xerces-C++ as the underlying XML parser. + // + using namespace xercesc; + + namespace xml = xsd::cxx::xml; + namespace parser = xsd::cxx::parser; + + XMLPlatformUtils::Initialize (); + + { + MemBufInputSource is ( + reinterpret_cast (buf), size, file, false); + is.setCopyBufToStream (false); + + unique_ptr parser (XMLReaderFactory::createXMLReader ()); + + parser->setFeature (XMLUni::fgSAX2CoreNameSpaces, true); + parser->setFeature (XMLUni::fgSAX2CoreNameSpacePrefixes, true); + parser->setFeature (XMLUni::fgXercesValidationErrorAsFatal, true); + + if (validate) + { + parser->setFeature (XMLUni::fgSAX2CoreValidation, true); + parser->setFeature (XMLUni::fgXercesSchema, true); + parser->setFeature (XMLUni::fgXercesSchemaFullChecking, false); + + // Xerces-C++ 3.1.0 is the first version with working multi import + // support. + // +#if _XERCES_VERSION >= 30100 + parser->setFeature (XMLUni::fgXercesHandleMultipleImports, true); +#endif + + // Initialize the schema cache. To detect schema errors we will + // need an error handler. + // + parser::error_handler eh; + xml::sax::bits::error_handler_proxy ehp (eh); + parser->setErrorHandler (&ehp); + + 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, + parser::error_handler::severity::fatal, + "unable to load schema"); + } + + eh.throw_if_failed (); + parser->setFeature (XMLUni::fgXercesUseCachedGrammarInParse, true); + +#if _XERCES_VERSION >= 30100 + parser->setFeature (XMLUni::fgXercesLoadSchema, false); +#endif + } + else + { + parser->setFeature (XMLUni::fgSAX2CoreValidation, false); + parser->setFeature (XMLUni::fgXercesSchema, false); + parser->setFeature (XMLUni::fgXercesSchemaFullChecking, false); + } + + os::time start; + + for (unsigned long i (0); i < iter; ++i) + { + root_p.pre (); + doc.parse (is, *parser); + root_p.post_root (); + } + + os::time end; + time = end - start; + } + + XMLPlatformUtils::Terminate (); + +#else + + XSD_UNUSED (validate); + + // Expat as the underlying XML parser. + // + XML_Parser xml_parser (XML_ParserCreateNS (0, ' ')); + string public_id (file); + + os::time start; + + for (unsigned long i (0); i < iter; ++i) + { + // Using the low-level Expat-specific API to parse the memory + // buffer. + // + root_p.pre (); + doc.parse_begin (xml_parser, public_id); + + XML_Parse (xml_parser, buf, size, 1); + + doc.parse_end (); + root_p.post_root (); + + XML_ParserReset (xml_parser, 0); + } + + os::time end; + time = end - start; + + XML_ParserFree (xml_parser); + +#endif + + 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 1; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/xsd-examples/cxx/parser/performance/gen.cxx b/xsd-examples/cxx/parser/performance/gen.cxx new file mode 100644 index 0000000..5c11343 --- /dev/null +++ b/xsd-examples/cxx/parser/performance/gen.cxx @@ -0,0 +1,79 @@ +// file : cxx/parser/performance/gen.cxx +// copyright : not copyrighted - public domain + +#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/parser/performance/gen.testscript b/xsd-examples/cxx/parser/performance/gen.testscript new file mode 100644 index 0000000..1dc6d66 --- /dev/null +++ b/xsd-examples/cxx/parser/performance/gen.testscript @@ -0,0 +1,9 @@ +# file : cxx/parser/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/parser/performance/test-50k.xml b/xsd-examples/cxx/parser/performance/test-50k.xml new file mode 100644 index 0000000..42e22f3 --- /dev/null +++ b/xsd-examples/cxx/parser/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/parser/performance/test.xsd b/xsd-examples/cxx/parser/performance/test.xsd new file mode 100644 index 0000000..450a800 --- /dev/null +++ b/xsd-examples/cxx/parser/performance/test.xsd @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xsd-examples/cxx/parser/performance/time.cxx b/xsd-examples/cxx/parser/performance/time.cxx new file mode 100644 index 0000000..c8c1002 --- /dev/null +++ b/xsd-examples/cxx/parser/performance/time.cxx @@ -0,0 +1,46 @@ +// file : cxx/parser/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/parser/performance/time.hxx b/xsd-examples/cxx/parser/performance/time.hxx new file mode 100644 index 0000000..a22f671 --- /dev/null +++ b/xsd-examples/cxx/parser/performance/time.hxx @@ -0,0 +1,110 @@ +// file : cxx/parser/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