Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add ByteSize impl for CString#497

Merged
wcampbell0x2a merged 2 commits into
masterfrom
add-bytes-to-cstring
Nov 2, 2024
Merged

Add ByteSize impl for CString#497
wcampbell0x2a merged 2 commits into
masterfrom
add-bytes-to-cstring

Conversation

@wcampbell0x2a
Copy link
Copy Markdown
Collaborator

  • Use the new dynamic bytes attribute to apply to CString, which in many protocols you already have the size of the CString, so might as well use it

* Use the new dynamic bytes attribute to apply to CString, which
  in many protocols you already have the size of the CString, so might
  as well use it
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for e130d8d

Click to view benchmark
Test Base PR %
count_from_u8_specialize 98.7±0.63ns 100.1±5.48ns +1.42%
count_no_specialize 2.4±0.02µs 2.6±0.02µs +8.33%
count_specialize 100.0±0.67ns 100.9±1.74ns +0.90%
deku_read_bits 1175.5±21.31ns 1127.4±13.80ns -4.09%
deku_read_byte 4.9±0.05ns 4.6±0.05ns -6.12%
deku_read_enum 4.1±0.06ns 3.8±0.08ns -7.32%
deku_read_vec 30.2±0.31ns 31.4±0.50ns +3.97%
deku_write_bits 189.8±6.24ns 198.8±8.03ns +4.74%
deku_write_byte 25.8±0.38ns 25.8±0.43ns 0.00%
deku_write_enum 23.9±0.39ns 24.1±1.30ns +0.84%
deku_write_vec 437.2±5.52ns 433.4±13.06ns -0.87%
read_all 4.3±0.07µs 5.0±0.04µs +16.28%
read_all_bytes 4.8±0.11µs 4.3±0.04µs -10.42%

Comment thread src/impls/cstring.rs

#[should_panic(expected = "Incomplete(NeedSize { bits: 8 })")]
case(&[b't', b'e', b's', b't'], CString::new("test").unwrap(), &[]),
case(&[b't', b'e', b's', b't'], None, CString::new("test").unwrap(), &[]),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought of a new test, what happens when no null byte is present

and, what happens when it's the correct len, but no nul byte present

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these are represented by 141cc5b

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 2, 2024

Benchmark for c01eb5b

Click to view benchmark
Test Base PR %
count_from_u8_specialize 115.2±1.16ns 91.2±1.58ns -20.83%
count_no_specialize 2.5±0.05µs 2.6±0.01µs +4.00%
count_specialize 102.5±1.26ns 96.8±1.30ns -5.56%
deku_read_bits 1163.9±9.14ns 1174.8±23.60ns +0.94%
deku_read_byte 4.5±0.04ns 4.5±0.06ns 0.00%
deku_read_enum 3.8±0.07ns 3.8±0.06ns 0.00%
deku_read_vec 47.1±0.89ns 30.1±0.19ns -36.09%
deku_write_bits 187.4±5.62ns 209.7±7.88ns +11.90%
deku_write_byte 26.1±0.43ns 26.1±0.40ns 0.00%
deku_write_enum 23.9±0.41ns 23.9±0.40ns 0.00%
deku_write_vec 449.4±7.82ns 431.0±4.73ns -4.09%
read_all 5.0±0.02µs 5.0±0.03µs 0.00%
read_all_bytes 5.1±0.29µs 4.2±0.03µs -17.65%

@wcampbell0x2a wcampbell0x2a merged commit 35b1d44 into master Nov 2, 2024
@wcampbell0x2a wcampbell0x2a deleted the add-bytes-to-cstring branch November 2, 2024 20:01
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