Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created August 1, 2020 12:22
Show Gist options
  • Select an option

  • Save kshirsagarsiddharth/08fe40dc1fcb8bfe3218f97331b7c6f4 to your computer and use it in GitHub Desktop.

Select an option

Save kshirsagarsiddharth/08fe40dc1fcb8bfe3218f97331b7c6f4 to your computer and use it in GitHub Desktop.
byte concatenation vs io.BytesIO
# 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