The Following 2 Users Say Thank You to thp For This Useful Post: | ||
![]() |
2010-04-26
, 17:45
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#42
|
I agree, although with good formatting and use of descriptive variable names, code can be highly self-documenting.
And I wonder if use of in-line comments versus separate-line comments makes a difference? Greg, can you test that also?
![]() |
2010-04-26
, 17:54
|
|
Posts: 1,684 |
Thanked: 1,562 times |
Joined on Jun 2008
@ Austin, TX
|
#43
|
Yup can do - working through my code at the moment - still working with the commented version (With less empty spaces) at the moment - so once i'm done i'll do 2 versions, one inline and one new lines... will see what happens...
I'm also intrigued as i know nothing about pyo files?! - am i amble to compile my python files to make them run faster?
Sorry if it's obvious - really am still very new to this
Some tips for experts:
* When the Python interpreter is invoked with the -O flag, optimized code is generated and stored in ‘.pyo’ files. The optimizer currently doesn't help much; it only removes assert statements. When -O is used, all bytecode is optimized; .pyc files are ignored and .py files are compiled to optimized bytecode.
* Passing two -O flags to the Python interpreter (-OO) will cause the bytecode compiler to perform optimizations that could in some rare cases result in malfunctioning programs. Currently only __doc__ strings are removed from the bytecode, resulting in more compact ‘.pyo’ files. Since some programs may rely on having these available, you should only use this option if you know what you're doing.
* A program doesn't run any faster when it is read from a ‘.pyc’ or ‘.pyo’ file than when it is read from a ‘.py’ file; the only thing that's faster about ‘.pyc’ or ‘.pyo’ files is the speed with which they are loaded.
* When a script is run by giving its name on the command line, the bytecode for the script is never written to a ‘.pyc’ or ‘.pyo’ file. Thus, the startup time of a script may be reduced by moving most of its code to a module and having a small bootstrap script that imports that module. It is also possible to name a ‘.pyc’ or ‘.pyo’ file directly on the command line.
* The module ‘compileall’{} can create ‘.pyc’ files (or ‘.pyo’ files when -O is used) for all modules in a directory.
The Following 4 Users Say Thank You to epage For This Useful Post: | ||
![]() |
2010-04-26
, 17:56
|
|
Posts: 1,684 |
Thanked: 1,562 times |
Joined on Jun 2008
@ Austin, TX
|
#44
|
Yup can do - working through my code at the moment - still working with the commented version (With less empty spaces) at the moment - so once i'm done i'll do 2 versions, one inline and one new lines... will see what happens...
I'm also intrigued as i know nothing about pyo files?! - am i amble to compile my python files to make them run faster?
Sorry if it's obvious - really am still very new to this
The Following User Says Thank You to epage For This Useful Post: | ||
![]() |
2010-04-26
, 18:33
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#45
|
![]() |
2010-04-26
, 22:58
|
|
Posts: 1,635 |
Thanked: 1,816 times |
Joined on Apr 2008
@ Manchester, England
|
#46
|
The Following User Says Thank You to lcuk For This Useful Post: | ||
![]() |
2010-04-27
, 00:00
|
Posts: 74 |
Thanked: 142 times |
Joined on Oct 2009
@ Chicago, US
|
#47
|
The Following 5 Users Say Thank You to pinsh For This Useful Post: | ||
![]() |
2010-04-27
, 14:00
|
|
Posts: 1,684 |
Thanked: 1,562 times |
Joined on Jun 2008
@ Austin, TX
|
#48
|
epage
of course comments are important in debugging and reading back code - which is why i said we like them
it does serve as a proof of concept over page after page of whitespace and comment overbloat (i am guilty of this!) and in part why I said about removing them as a build option and not from the source totally.
since this is effectively what the .pyc compiled file should do I doubt we will need to go to such extreme measures.
good that people are getting involved thoughenjoying this thread
The Following 3 Users Say Thank You to epage For This Useful Post: | ||
![]() |
2010-04-27
, 14:29
|
|
Posts: 1,684 |
Thanked: 1,562 times |
Joined on Jun 2008
@ Austin, TX
|
#49
|
$ python -m cProfile -o .profile PROGRAM $ python -m pstats .profile > sort tottime > show
![]() |
2010-04-27
, 14:47
|
|
Posts: 1,012 |
Thanked: 817 times |
Joined on Jul 2007
@ France
|
#50
|
The Following User Says Thank You to Khertan For This Useful Post: | ||
![]() |
Tags |
performance, python |
Thread Tools | |
|
But you are right - using xrange() is faster, because it can generate items "on the fly" whereas range() creates a list first.
See also: http://diveintopython3.org/porting-c...o3.html#xrange