bytebuf-2-join_map_bytes.py 383 B

123456789101112
  1. # Doing some operation on bytearray
  2. # Pretty weird way - map bytearray thru function, but make sure that
  3. # function return bytes of size 1, then join them together. Surely,
  4. # this is slowest way to do it.
  5. import bench
  6. def test(num):
  7. for i in iter(range(num//10000)):
  8. ba = bytearray(b"\0" * 1000)
  9. ba2 = b''.join(map(lambda x:bytes([x + 1]), ba))
  10. bench.run(test)