<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: text</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/text.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2010-01-28T13:28:07+00:00</updated><author><name>Simon Willison</name></author><entry><title>Reexamining Python 3 Text I/O</title><link href="https://simonwillison.net/2010/Jan/28/python3/#atom-tag" rel="alternate"/><published>2010-01-28T13:28:07+00:00</published><updated>2010-01-28T13:28:07+00:00</updated><id>https://simonwillison.net/2010/Jan/28/python3/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="http://www.dabeaz.com/blog/2010/01/reexamining-python-3-text-io.html"&gt;Reexamining Python 3 Text I/O&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Python 3.1’s IO performance is a huge improvement over 3.0, but still considerably slower than 2.6. It turns out it’s all to do with Python 3’s unicode support: When you read a file in to a string, you’re asking Python to decode the bytes in to UTF-8 (the new default encoding) at the same time. If you open the file in binary mode Python 3 will read raw bytes in to a bytestring instead, avoiding the conversion overhead and performing only 4% slower than the equivalent code in Python 2.6.4.


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/david-beazley"&gt;david-beazley&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/io"&gt;io&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/performance"&gt;performance&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/python3"&gt;python3&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/text"&gt;text&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/unicode"&gt;unicode&lt;/a&gt;&lt;/p&gt;



</summary><category term="david-beazley"/><category term="io"/><category term="performance"/><category term="python"/><category term="python3"/><category term="text"/><category term="unicode"/></entry></feed>