Skip to content

Instantly share code, notes, and snippets.

@themperek
Created March 10, 2016 19:04
Show Gist options
  • Save themperek/36353f59c9143acdb59e to your computer and use it in GitHub Desktop.
Save themperek/36353f59c9143acdb59e to your computer and use it in GitHub Desktop.
import time
from array import array
import numpy as np
buff = array('B')
x = np.empty([], dtype=np.uint8)
t0 = time.time()
for _ in range(1000):
buff.extend(array('B', '\x00' * 8000))
print '1', time.time() - t0
msg = bytearray()
t0 = time.time()
for _ in range(1000):
msg.extend('\x40' * 8000)
print '2', time.time() - t0
import collections
q = collections.deque()
t0 = time.time()
for _ in range(1000):
q.append(array('B', [0]*8000))
print '3', time.time() - t0
q = collections.deque()
t0 = time.time()
for _ in range(1000):
q.append(array('B', '\x00' * 8000))
print '4', time.time() - t0
x = '\x00\x00'
q = collections.deque()
t0 = time.time()
for _ in range(1000):
x = x + '\x00' * 8000
print '5', time.time() - t0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment