1

I am using mongo db for fast write to database, so that main application will not be affected at all.

For some reason importing pymongo takes much longer (~0.4 secs), while there are much larger packages which take much less time to import.

Is there a reason for this? Something to be done about it? Does it make sense to use sockets / writing to server instead, because of this time issue?

a = time.time()
import pymongo
print(time.time()-a)    # 0.397

b = time.time()
import PyQt4
print(time.time()-b)    # 0.006
Keren Meron
  • 139
  • 3
  • 14
  • did you try to clean your modules caches? – DRPK Nov 13 '17 at 12:33
  • How do I do this? And why would this affect only the pymongo package? I've tried this test several times on several occasions, always the same results. – Keren Meron Nov 13 '17 at 16:12
  • You asked a nice question and you are right! but when i saw pymongo requerments i got pymongo made by a lot of *.py or non binary ( not *.c, *.h *.whl or any kind of c/c++ binary files ) files!!but other packages like pyqt made by their original parents codes ( c/c++ )! non binary packages ( specialy c or c++ ) are much faster than .py files! because they are low level machine languages ( and python is based on c ), and also other common packages, are better than pymong on object_oriented_programming. pymongo is poor on its local_addressing and ram_buffer_handling! – DRPK Nov 13 '17 at 18:23
  • and... what do you think? To limit your research about this issue; ( i recommend you to import its subclass, calc their response time, then you can find which of those sub classes are heavy! ) – DRPK Nov 13 '17 at 18:30
  • if you are ok with compiling; you can compile your code to .pyc file ... read : https://stackoverflow.com/questions/2998215/if-python-is-interpreted-what-are-pyc-files. do not worry! pyc is not a external method or anything else, sometimes python compile its file/modules to pyc files for caching them, pyc file is much faster than .py file. – DRPK Nov 13 '17 at 18:40
  • Thank you very much for the detailed response! I know which subclass is heavy, there is no going around that. Your answer made me think maybe to implement my code in C using the mongo C library, and calling it from a python interface. Regarding .pyc - it is automatically generated for me when I run my .py file for the first time. I assume when I run the .py file, the .pyc file is being run (and not that I need to run .pyc explicitly). – Keren Meron Nov 13 '17 at 21:25

0 Answers0