Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NumString, usize based string #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Wicpar
Copy link
Contributor

@Wicpar Wicpar commented Dec 25, 2022

  • Added usize based string
  • Added it to benchmarks
  • it's a LOT faster than SmallString.
  • still missing most functions and a bit of docs, but nothing to large, just copy paste the array_string ones.

…enchmark. At least 50% performance over array_string
@paulocsanz
Copy link
Owner

Pretty cool trick, seems promising! Does that also work with u128, and possibly with multiple fields? So we can get a bigger string than 8 ASCII characters? Is usize instead of u64 intentional btw?

There seems to be a lot of future in this!

@Wicpar
Copy link
Contributor Author

Wicpar commented Dec 26, 2022

Usize guarantees maximum speed as it will always be a register.
U64 seems natural but in the end numtraits are not the way to go.
Maybe i'll try a generalized case since consts are not stable enough to be used effectively.
We could do u128 without issues but i expect it to be a lot slower.
In essence all that is needed is a bit field since all that is done is shifting things around while preserving endianness for instant str transmute.

@Wicpar
Copy link
Contributor Author

Wicpar commented Dec 26, 2022

In my benchmark it took 1 cycle to copy, 4 cycles to from_str, 5 cycles to push_str.
It will be pretty hard to beat that, at least on an arm cpu.
For u128 each operation on x86 using sse is 2 cycles on most cpus, but there could be sse magic to shave a few instructions so it could be almost as fast as the usize one.

It would also be worth it to test on terget arch=native, and maybe even with avx 2 256 bit registers. (512 is just too rare to test)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants