Created
August 1, 2020 12:22
-
-
Save kshirsagarsiddharth/08fe40dc1fcb8bfe3218f97331b7c6f4 to your computer and use it in GitHub Desktop.
byte concatenation vs io.BytesIO
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
| # then why not simply use the above mentioned. | |
| # optimization and performance | |
| import io | |
| import time | |
| start = time.time() | |
| buffer = b"" | |
| for i in range(0,90000): | |
| buffer += b"Hello World" | |
| end = time.time() | |
| total = end - start | |
| print(total) | |
| start = time.time() | |
| buffer = io.BytesIO() | |
| for i in range(0,90000): | |
| buffer.write(b"Hello World") | |
| end = time.time() | |
| total = end - start | |
| print(total) | |
| """ | |
| 1.8411164283752441 | |
| 0.01295328140258789 | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment