You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Added writer
- Adapted tests to use writer
- Converted FastByteReader methods into public trait functions
- Added those traits for each endianness for both writers and readers
- Updated README.md
- Updated dependencies (half 2.4.1 -> 2.5.0)
Benchmarking it is rather difficult since the compiler will do anything to optimize the call out completely (not run the code, I don't mean make it faster).
48
-
However, instructions don't lie, and I did manage to create a benchmark, present around line 2256 in [lib.rs](src/lib.rs#L2286-L2314).<br/>
49
+
However, instructions don't lie, and I did manage to create a benchmark, present around line 2322 in [lib.rs](src/lib.rs#L2322-L2351).<br/>
49
50
In [Compiler Explorer](https://rust.godbolt.org/z/PfhWzGnnG), you can also see for yourself the instructions for each function.
50
51
51
52
Running it on my machine, in debug mode, it is around 150% to 200% faster than `try_into`. In release mode, it is closer to only 20% faster.
52
53
> [!NOTE]
53
54
> While I am very confident that this micro-optimization is faster than the existing solutions, I stand by this only until I'm otherwise corrected.
54
55
55
56
## Usage
57
+
There are several-prebuilt readers/writers available, driven by traits.<br/>For reader traits it is:
- For reader implementations, there is [FastByteReader](src/reader.rs#L4-L51), [NetworkReader](src/reader.rs#L53-L98), [LittleReader](src/reader.rs#L100-L145), and [NativeReader](src/reader.rs#L147-L193).
- For writer implementations, there is [FastByteWriter](src/writer.rs#L3-L71), [NetworkWriter](src/writer.rs#L73-L139), [LittleWriter](src/writer.rs#L141-L207), and [NativeWriter](src/writer.rs#L209-L275).
68
+
69
+
You might be wondering... why does FastByteReader and FastByteWriter exist? Well, it is to enable cursed functionality such as switching between different endianness.
70
+
At the heart of it, all these implementations are incredibly simple to re-implement in your own structs, you can even do a hybrid reader/writer.
71
+
56
72
### Fast Byte Reader
57
73
If you want the fastest possible reader without going into completely unsafe territory, then you should use the FastByteReader.<br/>
58
74
Simply, it is an iterator-like reader where reading a type will result in consuming up the reader.<br/>
59
75
There are no results/options here, it will simply panic if you attempt to read bytes that don't exist. Thus, using this reader means the expected input has a very predictable content.
If you want a more "hands on" reader implementation with a bit more protection and nicer panic messages, this is the reader for you. It is slower than the fast reader (it has 13 instructions vs 9 instructions for the fast reader) because it has an index and additional bound check.
125
+
### Fast Byte Writer
126
+
If you want the fast writer with no particular endian-ness, without going into completely unsafe territory, then you should use the FastByteWriter.<br/>
0 commit comments