This repository was archived by the owner on May 31, 2025. It is now read-only.
Don't use argument unpacking on strings#57
Closed
eric-wieser wants to merge 2 commits intoros:indigo-develfrom
Closed
Don't use argument unpacking on strings#57eric-wieser wants to merge 2 commits intoros:indigo-develfrom
eric-wieser wants to merge 2 commits intoros:indigo-develfrom
Conversation
Contributor
Author
|
Ouch! In [1]: import struct
In [2]: data = b" "*100000
In [3]: % timeit struct.pack('100000s',data) # with this patch
The slowest run took 4.30 times longer than the fastest. This could mean that an intermediate result is being cached
100000 loops, best of 3: 15.3 µs per loop
In [4]: % timeit struct.pack('100000B',*data) # without it
100 loops, best of 3: 7.48 ms per loop |
Contributor
Author
|
And at the extreme: In[1]: import struct
In[2]: data = b" " * 1000000000
In[3]: %timeit struct.pack('s', data)
The slowest run took 7.66 times longer than the fastest. This could mean that an intermediate result is being cached
1000000 loops, best of 3: 487 ns per loop
In[4]: %timeit struct.pack('B', *data)
MemoryError |
test/test_genpy_generator.py
Outdated
|
|
||
| assert "chr(0)*1" == default_value(msg_context, 'uint8[1]', 'roslib') | ||
| assert "chr(0)*4" == default_value(msg_context, 'uint8[4]', 'roslib') | ||
| assert b'\0' == eval(default_value(msg_context, 'uint8[1]', 'roslib') |
Member
There was a problem hiding this comment.
Invalid syntax: lacks trailing ).
Contributor
Author
There was a problem hiding this comment.
Thanks! I had no idea why the marker was pointing at the start of the line in the traceback
Contributor
Author
|
I think it would make a lot more sense for every assertion in this test of be of the form |
Contributor
Author
|
These tests now fail because the python output of the generator has changed. At some point I'll update the expected output files to match the new output |
`struct.pack('5s', b'abcde')` works just fine for me on 3.5.0
And so `chr` is also not safe. `b'\0' works fine in both versions.
Member
|
Thank you for the patch. Merged to kinetic-devel in #63. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
struct.pack('5s', b'abcde')works just fine for me on 3.5.0. Argument unpacking a string is going to be a big performance hit for long strings too