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 ::=
T1 ::= INTEGER (25..30)

Test1 ::=
first T1,
second T1

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

Integer11 ::= INTEGER (0..32000)

Test3 ::=
first T1,
second T1,
third Integer11,
fourth Integer11

Here's an encoding using XML:


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.


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:

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.