[Suggestion] speeding up print
In both Pythonista versions, console output is pretty slow. For example,
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.
print 'something'statement from auto-complete in Pythonista 2, and replace it exclusively with
print('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 for
print(something, another_thing), unless you import
__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 as
print something, just like
6+7is the same as
6+(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 than
print foo, barbecause 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.