Skip to content

Performance tests

Adam Strojek edited this page Apr 30, 2019 · 2 revisions

Due to the nature of XXTEA encoding and that Danfoss eTRVs are big-endian devices we need to perform a lot of byte swapping operations. As you can read on the page of xxtea library that is used in the project:

The XXTEA algorithm takes a 128-bit key and operates on an array of 32-bit integers (at least 2 integers), but it doesn't define the conversions between bytes and array. Due to this reason, many XXTEA implementations out there are not compatible with each other. This means that all data structures are not only encoded in big-endian but also the whole encoding process is done in big-endian. Each set of 4 bytes is treated as a separate integer that is encoded in this order. To allow decoding and encoding on native endianness of machine we need to perform byte swap in chunks of the size that equals to 32-bit integer size (4 bytes). Later we reverse this process again to restore big-endian data structures.

A number of this byte swap operations is significant and it requires to select the best algorithm that will perform this operation in a reasinable way. In file tests/performance/byte_order.py you can find the simple script for testing this.

Here is a simple summary of performance tests:

4 bytes 8 bytes 16 bytes
byteorder_list_chunks_bytes 2.74568 secs 3.05940 secs 3.79910 secs
byteorder_list_chunks_bytearray 2.52049 secs 2.92091 secs 3.87355 secs
byteorder_list_chunks_bytearray_reverse 3.40204 secs 3.83216 secs 4.51576 secs
byteorder_repack_chunks 2.65100 secs 3.61871 secs 7.37578 secs
byteorder_int_chunks 8.73652 secs 11.11495 secs 8.88605 secs

Clone this wiki locally