gpt4 book ai didi

每次循环后 Python 保存到磁盘的速度变慢

转载 作者:行者123 更新时间:2023-12-03 21:35:56 25 4
gpt4 key购买 nike

在 Linux 系统上通过 numpy.save() 保存超过 1000 个循环会变慢。是什么导致了这个问题?

from time import time
import numpy as np

arr = np.ones([1080, 1920, 3], dtype=np.uint8)
path = "/tmp/testArray.{0}"

runrange = range(1000)

for i in runrange :
t = time()
np.save(path.format(i), arr)
print time()-t

它从 0.011 开始,然后上升到 0.106,最终在 0.19 左右

最佳答案

我知道这是一个古老/古老的帖子。但是,我无法重现问题行为 - 如果有的话,随着时间的推移它会变得稍微快一些。

from time import time

from matplotlib import pyplot as plt
import numpy as np

arr = np.ones((1080, 1920, 3), dtype=np.uint8)
path = "testArray.{0}"
times = []

for i in range(1_000):
t = time()
np.save(path.format(i), arr)
times.append((time() - t) * 1_000)

plt.figure(figsize=(9, 9))
plt.plot(range(1_000), times)
plt.savefig('time.png')

在 Win10 上测试使用 Python 3.9.1numpy==1.20.1

关于每次循环后 Python 保存到磁盘的速度变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35739839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com