Effacer les filtres
Effacer les filtres

importing a package is very slow

2 vues (au cours des 30 derniers jours)
covariant_cat
covariant_cat le 7 Juin 2018
Modifié(e) : covariant_cat le 7 Juin 2018
Say I have two packages:
+pack1
-- func1.m
-- func1_no_import.m
+pack2
Pack1 contains the following code:
function func1()
import('pack2.*');
function func1_no_import()
Then I test how much time it takes to run func1 3 million times:
import('pack1.*')
tic;
for i = 1:3000000
func1;
end
toc;
Elapsed time is 6.679269 seconds.
If you do the same thing in python, it takes less than half a second.
import time
start = time.time()
for i in range(3000000):
import os
end = time.time()
print(end - start)
0.3926999568939209
Also compare it with a control experiment where no import is performed.
import('pack1.*')
tic;
for i = 1:3000000
func1_no_import;
end
toc;
Elapsed time is 0.100767 seconds.
The main thing I don't understand is that since I heard that import is statically analyzed by Matlab (that is, it doesn't matter where you put the import statement in the function. https://stackoverflow.com/questions/37386754/why-can-you-import-a-package-after-using-its-content-in-a-function ). Why couldn't the cache of the function (I know that function contents are cached in Matlab) store the result of the import instead of running it 3 million times?

Réponses (0)

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by