import cProfile
import uuid
from http.client import HTTPResponse
s = uuid.uuid1().bytes * 10000
def r0():
for i in range(100000):
s
def r1():
for i in range(100000):
memoryview(s)
def r2():
for i in range(100000):
memoryview(s).tobytes()
def r3():
b = bytearray(len(s))
for i in range(100000):
b[:] = s
def r4():
b = bytearray(len(s))
b = memoryview(b)
for i in range(100000):
b[:] = s
def r5():
for i in range(100000):
bytearray(len(s))
def r6():
for i in range(100000):
bytearray(s)
def r7():
from copy import deepcopy
for i in range(100000):
deepcopy(s)
if __name__ == '__main__':
cProfile.run('r0()')
cProfile.run('r1()')
cProfile.run('r2()')
cProfile.run('r3()')
cProfile.run('r4()')
cProfile.run('r5()')
cProfile.run('r6()')
cProf
【笔记】bytes和bytearray还有memoryview
最新推荐文章于 2024-06-22 12:38:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)