Тестирование в IPython:
np.random.seed(123)
# arrays:
a = np.random.randint(0,1000,10000)
b = np.random.randint(0,1000,10000)
%%timeit -r 10 -n 10
plt.scatter(a, b)
plt.close()
54.7 ms ± 1.43 ms per loop (mean ± std. dev. of 10 runs, 10 loops each)
# lists
c = [f for f in a]
d = [f for f in b]
%%timeit -r 10 -n 10
plt.scatter(c, d)
plt.close()
154 ms ± 5.07 ms per loop (mean ± std. dev. of 10 runs, 10 loops each)
Похоже, что построение массивов здесь происходит быстрее.
Тестирование большего количества случаев различной длины:
#length|mean|sd
lists = [
(10000, 154, 5.07),
(1000, 33 , 0.235),
(100, 21, 0.198),
(10, 19.4, 0.937)
]
arrays = [
(10000, 54.7, 1.43),
(1000, 21.8, 1.51),
(100,18.4, 1.16),
(10, 18.1, 1.87)
]
# convert to arrays... for faster plotting ;)
lists = np.array(lists)
arrays = np.array(arrays)
plt.errorbar(lists[:,0], lists[:,1], yerr=lists[:,2], color = 'orange', label='lists', fmt='o')
plt.errorbar(arrays[:,0], arrays[:,1], yerr=arrays[:,2], color = 'teal', label='arrays', fmt='o')
plt.xscale('log')
plt.legend()
plt.xlabel('length of plotted data')
plt.ylabel('time per plot / ms')
![enter image description here](https://i.stack.imgur.com/UR89s.png)
Редактировать:
Только что увидел, что вы смотрите на поплавки.Я переделал эксперимент с поплавками, и результаты почти такие же:
#data generation:
np.random.seed(123)
a = np.random.rand(10000) * 1000
b = np.random.rand(10000) * 1000
lists = [
(10000, 155, 13.6),
(1000, 33 , 0.443),
(100, 21, 0.436),
(10, 19.1, 1.09)
]
arrays = [
(10000, 54.5, 3.24),
(1000, 21.6, 1.97),
(100, 18.6, 1.61),
(10, 19.4, 1.51)
]