Ask Your Question

Different runtime programs

asked 2018-10-24 10:59:00 -0500

updated 2019-03-13 10:23:56 -0500

Hello!Why does the speed of performance of functions differ depending on where they are launched? If I run in the console - program runs faster than in IDE (I use Wing Pro) Example.

Execution time in console:3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40)
forLoop : 1.8672226498562265
listComp : 1.0452214996682148
mapCall : 0.5306503870825039
genExpr : 1.427833488166335
genFunc : 1.4664546781685468

Execution time in IDE:3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40)
forLoop : 4.45649404998894
listComp : 1.9458866622428665
mapCall : 0.5576458305684584
genExpr : 12.455734571997347
genFunc : 12.939494802034947

I use a small function

def timer(func, *pargs, **kargs):
        start = time.clock()
        for i in repslist:
                ret = func(*pargs, **kargs)
        elapsed = time.clock() - start
        return (elapsed, ret)

For some reason, different execution times in the console and IDE

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-11-08 13:43:00 -0500

updated 2019-03-16 12:08:34 -0500

The slower cases are running with the debugger enabled.  Debug overhead is proportional to number of byte codes executed so something like nested Python for loops will incur a lot of overhead while most real code does not because compute-intensive looping is actually done in C code in Python's builtins, standard library, or third party modules.  I think this is why the genExpr and genFunc cases are so bad -- the way they are implemented is churning through a lot of Python byte codes.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-10-24 10:59:00 -0500

Seen: 362 times

Last updated: Mar 16 '19