-
-
Notifications
You must be signed in to change notification settings - Fork 184
Use bytearray for buffer in _UnixWritePipeTransport #385
Conversation
|
benchmark: draintest.py master: socketpair:writev (#339) methane:unix-events-bytearray-buffer |
|
Another benchmark draintest2.py #339 : this pull request: |
|
More combination of chunksize. draintest3.py #339 : this pull request: So, when chunk is small (~10KB), When chunk is large (100KB), |
|
@socketpair Could you confirm draintest3.py bench? |
| self._loop.add_writer(self._fileno, self._write_ready) | ||
|
|
||
| self._buffer.append(data) | ||
| self._buffer += data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use .extend() seems it is faster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is bad knowhow: operator is faster than method, thanks to slot.
In [2]: def pluseq():
...: buf = bytearray()
...: for _ in range(1000):
...: buf += b'foo'
...:
In [3]: def extend():
...: buf = bytearray()
...: for _ in range(1000):
...: buf.extend(b'foo')
...:
In [4]: %timeit pluseq()
10000 loops, best of 3: 80.2 µs per loop
In [5]: %timeit extend()
10000 loops, best of 3: 135 µs per loopThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And more important: bytearray.extend() accepts sequence of integers [0, 255).
In [6]: buf = bytearray()
In [7]: buf += [1,2,3]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-d99af3f0cf4a> in <module>()
----> 1 buf += [1,2,3]
TypeError: can't concat list to bytearray
In [8]: buf.extend([1,2,3])
In [9]: buf
Out[9]: bytearray(b'\x01\x02\x03')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In [6]: buf = bytearray()
In [7]: buf += [1,2,3]
This should not be allowed. Supporting this would make life for other loop implementations harder with no obvious benefits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1st1 Yes, it raises TypeError, as you can see above.
what does that mean ? |
|
@socketpair I meant could you confirm draintest3.py measures right thing, and benchmark in you environment. |
|
Committed in 6f8f833. Thank you! |
fixes #384
This pull request is a control experiment of #339.