[Interest] Faster QXmlStreamWriter?

Thiago Macieira thiago.macieira at intel.com
Wed Apr 25 09:10:36 CEST 2018


On Tuesday, 24 April 2018 23:36:15 PDT Thiago Macieira wrote:
> 3) use the examples/corelib/serialization/convert tool[1] to
> convert to other formats
>  4) use the same tool with the "null" output to benchmark reading[2]
>  5) use the tool with binary JSON as source to benchmark writing

Attached is a sample shell session of how to use the tool and what it can do.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
$ #### Help options

$ ./convert --help
Usage: ./convert [options] [source] [destination]
Qt file format conversion tool

Options:
  -h, --help                    Displays this help.
  -I, --input-format <format>   Select the input format for the input file.
                                Available formats: auto, binary-json, cbor,
                                datastream, json, text, xml
  -O, --output-format <format>  Select the output format for the output file.
                                Available formats: auto, binary-json, cbor,
                                cbor-dump, datastream, datastream-dump, json,
                                null, text, xml
  -o, --option <options...>     Format-specific options. Use --format-options
                                to find out what options are available.
  --format-options <format>     Prints the list of valid options for --option
                                for the converter format <format>.

Arguments:
  [source]                      File to read from (stdin if none)
  [destination]                 File to write to (stdout if none)

$ ./convert --format-options cbor
The following options are available for format 'cbor':

convert-float-to-int=yes|no    Write integers instead of floating point, if no
                               loss of precision occurs on conversion.
float16=yes|always|no          Write using half-precision floating point.
                               If 'always', won't check for loss of precision.
float32=yes|always|no          Write using single-precision floating point.
                               If 'always', won't check for loss of precision.
signature=yes|no               Prepend the CBOR signature to the file output.

$ ./convert --format-options json
The following options are available for format 'json':

compact=no|yes              Use compact JSON form.
tjmaciei at tjmaciei-mobl1 ~/obj/qt/qt5/qtbase/examples/corelib/serialization/convert $ ./convert --format-options datastream
The following options are available for format 'datastream':

byteorder=host|big|little      Byte order to use.
version=<n>                    QDataStream version (default: Qt 5.0).

$ ./convert --format-options xml
The following options are available for format 'xml':

compact=no|yes              Use compact XML form.

$ #### Let's play with the tool. Get some JSON data then use the tool to convert

$ qtplugininfo --full-json  $QTOBJDIR/plugins/imageformats/libqgif.so | tee /tmp/data.json
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "gif"
        ],
        "MimeTypes": [
            "image/gif"
        ]
    },
    "className": "QGifPlugin",
    "debug": true,
    "version": 330496
}

$ ./convert /tmp/data.json 
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "gif"
        ],
        "MimeTypes": [
            "image/gif"
        ]
    },
    "className": "QGifPlugin",
    "debug": true,
    "version": 330496
}

$ ./convert -o compact=yes /tmp/data.json
{"IID":"org.qt-project.Qt.QImageIOHandlerFactoryInterface","MetaData":{"Keys":["gif"],"MimeTypes":["image/gif"]},"className":"QGifPlugin","debug":true,"version":330496}

$ ./convert -O text /tmp/data.json           
IID => org.qt-project.Qt.QImageIOHandlerFactoryInterface
MetaData => Keys => gif
MimeTypes => image/gif
className => QGifPlugin
debug => true
version => 330496

$ ./convert -O datastream-dump /tmp/data.json 
Map {
  QVariant(QString, "IID") => QVariant(QString, "org.qt-project.Qt.QImageIOHandlerFactoryInterface"),
  QVariant(QString, "MetaData") => Map {
    QVariant(QString, "Keys") => List [
      QVariant(QString, "gif")
    ],
    QVariant(QString, "MimeTypes") => List [
      QVariant(QString, "image/gif")
    ]
  },
  QVariant(QString, "className") => QVariant(QString, "QGifPlugin"),
  QVariant(QString, "debug") => QVariant(bool, true),
  QVariant(QString, "version") => QVariant(double, 330496)
}

$ ./convert -O xml /tmp/data.json  
<?xml version="1.0" encoding="UTF-8"?>
<map>
    <entry>
        <value type="string"><![CDATA[IID]]></value>
        <value type="string"><![CDATA[org.qt-project.Qt.QImageIOHandlerFactoryInterface]]></value>
    </entry>
    <entry>
        <value type="string"><![CDATA[MetaData]]></value>
        <map>
            <entry>
                <value type="string"><![CDATA[Keys]]></value>
                <list>
                    <value type="string"><![CDATA[gif]]></value>
                </list>
            </entry>
            <entry>
                <value type="string"><![CDATA[MimeTypes]]></value>
                <list>
                    <value type="string"><![CDATA[image/gif]]></value>
                </list>
            </entry>
        </map>
    </entry>
    <entry>
        <value type="string"><![CDATA[className]]></value>
        <value type="string"><![CDATA[QGifPlugin]]></value>
    </entry>
    <entry>
        <value type="string"><![CDATA[debug]]></value>
        <value type="bool">true</value>
    </entry>
    <entry>
        <value type="string"><![CDATA[version]]></value>
        <value type="number">330496</value>
    </entry>
</map>

$ ### Convert so some other formats:

$ ./convert -O binary-json /tmp/data.json /tmp/data.bjson

$ ./convert -O cbor /tmp/data.json /tmp/data.cbor

$ ./convert -o compact=yes -O xml /tmp/data.json /tmp/data.xml

$ ./convert -o byteorder=host -O datastream /tmp/data.json /tmp/data.ds 

$ v /tmp/data.*
-rw-r--r-- 1 tjmaciei users 276 abr 24 23:53 /tmp/data.bjson
-rw-r--r-- 1 tjmaciei users 141 abr 24 23:53 /tmp/data.cbor
-rw-r--r-- 1 tjmaciei users 168 abr 25 00:07 /tmp/data.compact-json
-rw-r--r-- 1 tjmaciei users 359 abr 24 23:58 /tmp/data.ds
-rw-r--r-- 1 tjmaciei users 269 abr 24 23:51 /tmp/data.json
-rw-r--r-- 1 tjmaciei users 825 abr 25 00:06 /tmp/data.xml

$ file /tmp/data.*
/tmp/data.bjson: data
/tmp/data.cbor:  Concise Binary Object Representation (CBOR) container (array) (map)
/tmp/data.compact-json: ASCII text, with no line terminators
/tmp/data.ds:    data
/tmp/data.json:  ASCII text
/tmp/data.xml:   XML 1.0 document, ASCII text, with very long lines

$ ./convert /tmp/data.bjson 
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "gif"
        ],
        "MimeTypes": [
            "image/gif"
        ]
    },
    "className": "QGifPlugin",
    "debug": true,
    "version": 330496
}

$ ./convert /tmp/data.cbor 
{
    "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
    "MetaData": {
        "Keys": [
            "gif"
        ],
        "MimeTypes": [
            "image/gif"
        ]
    },
    "className": "QGifPlugin",
    "debug": true,
    "version": 330496
}

$ ./convert /tmp/data.ds
Map {
  QVariant(QString, "IID") => QVariant(QString, "org.qt-project.Qt.QImageIOHandlerFactoryInterface"),
  QVariant(QString, "MetaData") => Map {
    QVariant(QString, "Keys") => List [
      QVariant(QString, "gif")
    ],
    QVariant(QString, "MimeTypes") => List [
      QVariant(QString, "image/gif")
    ]
  },
  QVariant(QString, "className") => QVariant(QString, "QGifPlugin"),
  QVariant(QString, "debug") => QVariant(bool, true),
  QVariant(QString, "version") => QVariant(double, 330496)
}

$ ### XML reading is broken

$ ./convert /tmp/data.xml  
1:176: Invalid XML Characters ''.

$ ./convert -O text /tmp/data.cbor
IID => org.qt-project.Qt.QImageIOHandlerFactoryInterface
MetaData => Keys => gif
MimeTypes => image/gif
className => QGifPlugin
debug => true
version => 330496

$ ./convert -O datastream-dump /tmp/data.cbor                       
Map {
  QVariant(QString, "IID") => QVariant(QString, "org.qt-project.Qt.QImageIOHandlerFactoryInterface"),
  QVariant(QString, "MetaData") => Map {
    QVariant(QString, "Keys") => List [
      QVariant(QString, "gif")
    ],
    QVariant(QString, "MimeTypes") => List [
      QVariant(QString, "image/gif")
    ]
  },
  QVariant(QString, "className") => QVariant(QString, "QGifPlugin"),
  QVariant(QString, "debug") => QVariant(bool, true),
  QVariant(QString, "version") => QVariant(qlonglong, 330496)
}

$ #### Dumps of the binary files

$ ../cbordump/cbordump --annotated /tmp/data.cbor
d9 d9 f7                                           # Tag 55799 (Self-describe CBOR; see Section 2.4.5 [RFC7049])
  a5                                               # Map length 5
    63                                             # Text string length 3
      49 49 44                                     # "IID"
    78 31                                          # Text string length 49
      6f 72 67 2e 71 74 2d 70 72 6f 6a 65 63 74    # "org.qt-project"
      2e 51 74 2e 51 49 6d 61 67 65 49 4f 48 61    # ".Qt.QImageIOHa"
      6e 64 6c 65 72 46 61 63 74 6f 72 79 49 6e    # "ndlerFactoryIn"
      74 65 72 66 61 63 65                         # "terface"
    68                                             # Text string length 8
      4d 65 74 61 44 61 74 61                      # "MetaData"
    a2                                             # Map length 2
      64                                           # Text string length 4
        4b 65 79 73                                # "Keys"
      81                                           # Array length 1
        63                                         # Text string length 3
          67 69 66                                 # "gif"
      69                                           # Text string length 9
        4d 69 6d 65 54 79 70 65 73                 # "MimeTypes"
      81                                           # Array length 1
        69                                         # Text string length 9
          69 6d 61 67 65 2f 67 69 66               # "image/gif"
    69                                             # Text string length 9
      63 6c 61 73 73 4e 61 6d 65                   # "className"
    6a                                             # Text string length 10
      51 47 69 66 50 6c 75 67 69 6e                # "QGifPlugin"
    65                                             # Text string length 5
      64 65 62 75 67                               # "debug"
    f5                                             # Simple Type true
    67                                             # Text string length 7
      76 65 72 73 69 6f 6e                         # "version"
    1a 00 05 0b 00                                 # Unsigned integer 0x50b00

$ xxd /tmp/data.bjson 
00000000: 7162 6a73 0100 0000 0c01 0000 0b00 0000  qbjs............
00000010: f800 0000 1b03 0000 0300 4949 4400 0000  ..........IID...
00000020: 3100 6f72 672e 7174 2d70 726f 6a65 6374  1.org.qt-project
00000030: 2e51 742e 5149 6d61 6765 494f 4861 6e64  .Qt.QImageIOHand
00000040: 6c65 7246 6163 746f 7279 496e 7465 7266  lerFactoryInterf
00000050: 6163 6500 950b 0000 0800 4d65 7461 4461  ace.......MetaDa
00000060: 7461 0000 6400 0000 0500 0000 5c00 0000  ta..d.......\...
00000070: 1403 0000 0400 4b65 7973 0000 1800 0000  ......Keys......
00000080: 0200 0000 1400 0000 0300 6769 6600 0000  ..........gif...
00000090: 8b01 0000 1408 0000 0900 4d69 6d65 5479  ..........MimeTy
000000a0: 7065 7300 1c00 0000 0200 0000 1800 0000  pes.............
000000b0: 0900 696d 6167 652f 6769 6600 8b01 0000  ..image/gif.....
000000c0: 0c00 0000 3000 0000 1b1a 0000 0900 636c  ....0.........cl
000000d0: 6173 734e 616d 6500 0a00 5147 6966 506c  assName...QGifPl
000000e0: 7567 696e 3100 0000 0500 6465 6275 6700  ugin1.....debug.
000000f0: 1a60 a100 0700 7665 7273 696f 6e00 0000  .`....version...
00000100: 0c00 0000 4c00 0000 c000 0000 dc00 0000  ....L...........
00000110: e800 0000                                ....

$ xxd /tmp/data.ds 
00000000: 7164 736c 0d00 0000 0800 0000 0005 0000  qdsl............
00000010: 000e 0000 0076 0065 0072 0073 0069 006f  .....v.e.r.s.i.o
00000020: 006e 0006 0000 0000 0000 0000 002c 1441  .n...........,.A
00000030: 0a00 0000 6400 6500 6200 7500 6700 0100  ....d.e.b.u.g...
00000040: 0000 0001 1200 0000 6300 6c00 6100 7300  ........c.l.a.s.
00000050: 7300 4e00 6100 6d00 6500 0a00 0000 0014  s.N.a.m.e.......
00000060: 0000 0051 0047 0069 0066 0050 006c 0075  ...Q.G.i.f.P.l.u
00000070: 0067 0069 006e 0010 0000 004d 0065 0074  .g.i.n.....M.e.t
00000080: 0061 0044 0061 0074 0061 0008 0000 0000  .a.D.a.t.a......
00000090: 0200 0000 1200 0000 4d00 6900 6d00 6500  ........M.i.m.e.
000000a0: 5400 7900 7000 6500 7300 0900 0000 0001  T.y.p.e.s.......
000000b0: 0000 000a 0000 0000 1200 0000 6900 6d00  ............i.m.
000000c0: 6100 6700 6500 2f00 6700 6900 6600 0800  a.g.e./.g.i.f...
000000d0: 0000 4b00 6500 7900 7300 0900 0000 0001  ..K.e.y.s.......
000000e0: 0000 000a 0000 0000 0600 0000 6700 6900  ............g.i.
000000f0: 6600 0600 0000 4900 4900 4400 0a00 0000  f.....I.I.D.....
00000100: 0062 0000 006f 0072 0067 002e 0071 0074  .b...o.r.g...q.t
00000110: 002d 0070 0072 006f 006a 0065 0063 0074  .-.p.r.o.j.e.c.t
00000120: 002e 0051 0074 002e 0051 0049 006d 0061  ...Q.t...Q.I.m.a
00000130: 0067 0065 0049 004f 0048 0061 006e 0064  .g.e.I.O.H.a.n.d
00000140: 006c 0065 0072 0046 0061 0063 0074 006f  .l.e.r.F.a.c.t.o
00000150: 0072 0079 0049 006e 0074 0065 0072 0066  .r.y.I.n.t.e.r.f
00000160: 0061 0063 0065 00                        .a.c.e.



More information about the Interest mailing list