Add a simple abstract class to implement custom encoding implementations.
It only requires to provide the encode and decoding methods base on the performance-based Span and it provides help methods to report invalid chars / bytes.
The byte/char count methods will re-use the encode and decode methods, as typically the implementation is very similar and the performance is not affected.
This class was already use in Metatron to implement the Persona encoding.
Also refactor the performance test app so we can run all the tests individually.
[x] Implement base class
[x] Compare performance
[x] Add tests
Performance comparison
The performance between a custom implementation on Encoding and on this class is practically the same. Thanks to the advance usage of Span, simplified in this class, the memory is 3x times better and consumes the same as the standard implementations of .NET.
In this case we compare a custom Shift-JIS implementation with the .NET implementation. The performance is worse than the .NET API provided encoding as they do optimizations at low-level with binary dictionaries. Our implementation is a typically use-case with conditions following the specs.
The values are good for a maximum use case of 5 MB of text (0.5 sec), the memory is great and the implementation is very simple.
Description
Add a simple abstract class to implement custom encoding implementations. It only requires to provide the encode and decoding methods base on the performance-based
Span
and it provides help methods to report invalid chars / bytes. The byte/char count methods will re-use the encode and decode methods, as typically the implementation is very similar and the performance is not affected. This class was already use in Metatron to implement the Persona encoding.Also refactor the performance test app so we can run all the tests individually.
Performance comparison
The performance between a custom implementation on
Encoding
and on this class is practically the same. Thanks to the advance usage of Span, simplified in this class, the memory is 3x times better and consumes the same as the standard implementations of .NET. In this case we compare a custom Shift-JIS implementation with the .NET implementation. The performance is worse than the .NET API provided encoding as they do optimizations at low-level with binary dictionaries. Our implementation is a typically use-case with conditions following the specs. The values are good for a maximum use case of 5 MB of text (0.5 sec), the memory is great and the implementation is very simple.Example