.

Python print performance

Perhaps this is kind of obvious, but I only realized this today: using the print statement in Python can cost you a lot of time!

When I'm hacking on a piece of code containing a large for-loop in some algorithm, I'm often printing the current iteration to the console to keep a tab on the progress.

Consider this trivial example:

j = 0
for i in xrange(4096**2):
    j += i
    print i

This outputs a fast scrolling list of integers so I can keep track of progress, but this results in the following running time on the console:

$ time python print_time.py
...
...
16777215

real    11m5.059s
user    1m16.077s
sys     1m8.568s

Running the same code without the print statement takes a lot less time:

$ time python print_time.py

real    0m13.585s
user    0m13.569s
sys     0m0.008s

Please correct me if I'm wrong, but my guess is it's not because of the performance of the print statement, but the ability of the console to process all that output.

posted on 13 Feb, 2010 to Python » view comments

I can has Spotify invite?

Does anyone have a Spotify beta invite to share with this poor Python programmer?

Thanks!

Edit: Got one, thanks a million!

posted on 04 Feb, 2010 to General » view comments

DIY 3D Scanner

A friend and I decided to take on the DIY 3D Scanner this weekend. Full instructuions can be found here.

Scroll down for videos of the result and photos of the setup. Notice the hollow face illusion.

posted on 17 Jan, 2010 to DIY » view comments