arrayop-3-bytearray_inplace.py 334 B

123456789101112
  1. # Array operation
  2. # Type: bytearray, inplace operation using for. What's good about this
  3. # method is that it doesn't require any extra memory allocation.
  4. import bench
  5. def test(num):
  6. for i in iter(range(num//10000)):
  7. arr = bytearray(b"\0" * 1000)
  8. for i in range(len(arr)):
  9. arr[i] += 1
  10. bench.run(test)