Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[Suggestion] speeding up print
-
In both Pythonista versions, console output is pretty slow. For example,
print
in my Mac terminal is noticeably faster than it is in Pythonista.print
-ing really long things can take quite a while, while it's still almost instant in a Mac terminal.I don't know if speed enhancements to this are possible, but if they were if welcome that change.
-
@Webmaster4o , I know this is not what you had in mind and not even sure it would be faster could be slower. But if you create an object to print to. Then inside the object, you have buffers for pages etc. you print to the screen when you decide to.but possibly reformatting/refactoring the input could speed up when you pump it out to the console. Eg. Remove all wrapping, go though and chop lines the max width of the console. But this is all guessing , only @omz really knows were the real bottlenecks are in the console code.
I just say, because I know you like to be challenged -
@Webmaster4o , I can see the hold up now. It's about scrolling. It's very clear from the test below
_cnt = 1000 print 'a' * _cnt for i in range(_cnt): print 'a'
-
I ran into this issue when making an ascii movie viewer, and I resorted to using a scene view, and plastering my text there.
-
I'm behind anything that speeds up pythonista. But on an only somewhat tangential thread, here's a proposal for Pythonista 2.
Remove the
print 'something'
statement from auto-complete in Pythonista 2, and replace it exclusively withprint('something')
since it's future proof for Python3, and I see no reason to encourage it's use. -
@Tizzy I don't think that would be a good idea.
print(something)
happens to do the same in both versions, but that isn't the case forprint(something, another_thing)
, unless you importprint_function
from__future__
in Python 2.(In case you're not aware of the difference:
print(something)
is not a function call in Python 2, it's exactly the same asprint something
, just like6+7
is the same as6+(7)
. When you have more than one argument, the difference becomes apparent because in that case, you're printing a tuple in Python 2, instead of two things, separated by a space, in Python 3.) -
In general, I would recommend trying to minimize the number of individual pieces of text that are printed. For example,
print 'foo ' + 'bar'
is faster thanprint foo, bar
because in the latter case, the two arguments are printed individually, which is generally more expensive. Also, in cases where you want to print several lines, consider joining them, e.g.:# Pretty slow: for line in some_list: print line # Faster: print '\n'.join(some_list)
-
@omz Right, but outside of changing my code, are there other improvements that could me made to yours? In general, I think speed improvements should not be up to the user. What makes the two print calls more expensive? Do you have unnecessary logic running every time? (e.g. The console sliding over logic happening on every statement) that could be shortened or eliminated?
Just wondering if there's anything @omz could do.
-
IDLE is even slower. I read somewhere that the python interpreter is really fast, but IDLE just prints the results slower.
I do think the speed issue would be on Pythonista's end.
-
I'll see what I can do.