Sunday, June 17, 2007

XML versus ASN.1

I don't know how widely the ASN.1 Packed Encoding Rules (PER) are used but here's an example of how much more verbose XML can be than PER.

Here's a simple ASN.1 definition:

FooBaz {1 2 0 0 6 3} DEFINITIONS ::=
BEGIN
T1 ::= INTEGER (25..30)

Test1 ::=
SEQUENCE {
first T1,
second T1
}

Test2 ::=
SEQUENCE {
first2 [0] T1 OPTIONAL,
second2 [1] T1 OPTIONAL
}

Integer11 ::= INTEGER (0..32000)

Test3 ::=
SEQUENCE {
first T1,
second T1,
third Integer11,
fourth Integer11
}
END

Here's an encoding using XML:

<Test3>
<first>29</first>
<second>30</second>
<third>63</third>
<fourth>31000</fourth>
</Test3>

Here's the PER. Note that it fits into 36 bits so the last 12 are irrelevant.

9401 ff91 8000

I make that 36 bits for PER and 112*8 = 896 bits for XML, a ratio of 1:25.

6 comments:

Graeme Burnett said...

So if for were shipping 30MB/s to the trading floor for example because we were using XML, we could cut this to 1.2MB/s - very impressive. I wonder how fast a PER parser would be?

John Dougan said...

what does it look like using the BER?

cinimod said...

I make it 14 bytes = 14*8 bits = 112 bits:

300d 0201 1d02 011e 0201 3f02 0279 18

cinimod said...

I've not carried out performance tests myself but there seem to be some satisified users of asn1c .

Graeme Burnett said...

So after nearly six years they've finally listened: http://www.fixtradingcommunity.org/pg/structure/tech-specs/high-performance-encoding-specifications

SBE is basically ASN.1 dressed up in FIX

Alexander Nasonov said...

ASN.1 is quite good but PER encoding (both aligned and unaligned) is horrible.