Closed DaWe35 closed 5 years ago
I see the point of the improvment! Thank you very much!
I think your first suggestion is correct! len()
is counting all elements of the list every time its used. If we the use append
and pop
methods to increase or decrease with 1, then for sure its faster to use self.stream_buffer_length
instead of len(array)
.
if someone has the reason to control every second the stream_buffer size, then your first solution is definitely the best way ...
5 commit: pop() changed to pop(0), I think it was a bug
Yes, it should be a FIFO stack, thanks!
Hmm. I don't know. It would be logical, but I think python already does that. There is a conversion about len(): https://stackoverflow.com/questions/699177/python-do-python-lists-keep-a-count-for-len-or-does-it-count-for-each-call
If you decide to use self.stream_buffer_length
instead of len(array)
, just ignore #6 (a16e9aa)commit.
i am thinking about it ... on the other hand, the stream_buffer should be almost 0 all the time, so its a bigger waste to count hundreds of +/- 1 operations per second, if you dont need them.
True. And what is with sys.getsizeof? :)
I can't update the documentation (https://www.unicorn-data.com/unicorn-binance-websocket-api.html), so if you want, you need to add get_stream_buffer_length()
True. And what is with sys.getsizeof? :)
Its because, if I count the size this way, its compare able to the self.total_received_bytes value. But if i use the size of the stream_buffer variable itself, its very different. not only the raw data is used in the size, also the metadata for the complete list object of the stream_buffer and we receive a json and convert it! But at least its not accurate information, we should switch to use the data from the stream_buffer itself.
I can't update the documentation (https://www.unicorn-data.com/unicorn-binance-websocket-api.html), so if you want, you need to add get_stream_buffer_length()
Thanks, I will do it asap!
Its done, changes are available in the new release: https://github.com/unicorn-data-analysis/unicorn-binance-websocket-api/blob/master/CHANGELOG.md#138
Cooool!
I needed a function that returns the number of items in buffer. If you find it useful, feel free to pull :) (And the performance of get_stream_buffer_length() is better than len(self.stream_buffer), but I don't think it matters very much.)