-
Notifications
You must be signed in to change notification settings - Fork 79
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
Improvements on precision of Throughput #183
Conversation
Improvements on precision of Throughput Measuring Mechanism. - Usage of timeit.default_timer() in tlstests.py instead of time.time(). - Measuring of the size for travelling data with the sys.getsizeof().
tests/tlstest.py
Outdated
connection.write(b"hello"*10000) | ||
h = connection.read(min=50000, max=50000) | ||
stopTime = time.clock() | ||
stopTime = timeit.default_timer() | ||
sizeofdata = sys.getsizeof(h)*2 |
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.
sys.getsizeof()
returns the size of allocated memory for the object, not the length of the string (actually transferred data).
See:
>>> import sys
>>> sys.getsizeof(bytearray(0))
48
>>> sys.getsizeof(bytearray(12))
61
len()
is entirely sufficient here
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.
Or differently defined and Interpreted:
sys.getsizeof() returns the size of an object in bytes. The object can be any type of object. All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific.
Whether len() returns the length (the number of items) of an object.
Therefore it seemed more accurate to measure the total size of the actual bytes instead of the number of the elements. Hence I'm not quite sure if len() is equally sufficient, which may seems like a good choice at first sight.
>>> h = b'hello'*10000
>>> len(h)
50000
>>> sys.getsizeof(h)
50037
Unless we are sure that this 37 bytes 'overhead' is never transmitted, I can agree with you.
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.
the "overhead" isn't transmitted - the socket transmits bytes, not objects
Usage of timeit.default_timer() in tlstests.py. Measuring of the size for travelling data with the len()
thanks! |
Improvements on precision of Throughput Measuring Mechanism.
This change is