I have updated the benchmark to now measure importing source w/o writing bytecode, importing source &amp; writing bytecode, and importing bytecode w/ source (as I don&#39;t care about sourceless import performance).<div><br>

</div><div>Now, before you look at these numbers, realize that I have not once tried to profile importlib to see where its hot spots are (only optimization I have done is cut down on the stat calls since Python 3.1 when I re-developed the ABCs). I&#39;m sure if I profiled the code and wrote key bits in C these performance numbers would improve reasonably quickly.</div>

<div><br></div><div>Anyway, on my 2.2 GHz MacBook, this leads to::</div><div><br></div><div>import.c</div><div><div>sys.modules [ 223337 223036 223362 ] best is 223362</div><div>Built-in module [ 23347 23319 23331 ] best is 23347</div>

<div>Bytecode w/ source [ 6624 6607 6608 ] best is 6624</div><div>Source w/o bytecode [ 4643 4674 4655 ] best is 4674</div><div>Source writing bytecode [ 2063 2145 2204 ] best is 2204</div><div><br></div><div>importlib</div>

<div><div>sys.modules [ 43423 43414 43426 ] best is 43426</div><div>Built-in module [ 9130 9115 9120 ] best is 9130</div><div>Bytecode w/ source [ 1554 1556 1556 ] best is 1556</div><div>Source w/o bytecode [ 1351 1351 1353 ] best is 1353</div>

<div>Source writing bytecode [ 786 843 810 ] best is 843</div></div><div><br></div><div>importlib / import.c:</div><div>sys.modules  19%</div><div>Built-in module  39%</div><div>Bytecode w/ source  23%</div><div>Source w/o bytecode  29%</div>

<div>Source writing bytecode  38%</div><div><br></div><div>What does this show? Stuff that requires a lot of I/O has the smallest performance difference (source writing bytecode), but where there is as little I/O as possible (bytecode w/ source) import.c wins as it has to do less. This is also why sys.modules is so damn fast; it&#39;s the smallest amount of C code you can run while importlib has standard Python calling overhead.</div>

<div><br></div><div>It should also be pointed out that importlib has fully implemented PEP 302 and intentionally has the loaders using their own exposed PEP 302 APIs. This means there are a lot more methods calls than in the C version, along with a lot less corners cut in the name of performance. So while importlib will be slower simply because it&#39;s implemented in C, it will also be slower because the darn thing is actually written to follow the PEPs we have along with making it easier for people to subclass and benefit from the import code.</div>

<div><br></div><div>Anyway, as I have said, I need to hit 100% compatibility when running the test suite -- run importlib.test.regrtest to see where it fails now; also read that file as it has notes as to why the known failures are happening -- before I start worrying about bootstrapping and performance and that will all be no sooner than Python 3.3.</div>

<br><div class="gmail_quote">On Thu, Jul 15, 2010 at 04:55, Nick Coghlan <span dir="ltr">&lt;<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Thu, Jul 15, 2010 at 4:06 PM, Brett Cannon &lt;<a href="mailto:brett@python.org">brett@python.org</a>&gt; wrote:<br>
&gt;&gt; In any case, here my results under a Linux system:<br>
&gt;&gt;<br>
&gt;&gt; $ ./python -m importlib.test.benchmark<br>
&gt;&gt; sys.modules [ 323782 326183 326667 ] best is 326667<br>
&gt;&gt; Built-in module [ 33600 33693 33610 ] best is 33693<br>
&gt;&gt;<br>
&gt;&gt; $ ./python -m importlib.test.benchmark -b<br>
&gt;&gt; sys.modules [ 1297640 1315366 1292283 ] best is 1315366<br>
&gt;&gt; Built-in module [ 58180 57708 58057 ] best is 58180<br>
&gt;<br>
&gt; And this is what might make evaluating importlib tough; while the<br>
&gt; performance is 25% of what it is for import.c, being able to import<br>
&gt; over 300,000 times/second is still damn fast.<br>
<br>
</div>Yeah, I think the numbers where the filesystem gets involved are going<br>
to be more relevant. Modules that have already been cached and those<br>
built in to the executable aren&#39;t likely to dominate interpreter and<br>
application startup times (which is the main thing I&#39;m worried about<br>
seeing regress).<br>
<br>
Cheers,<br>
Nick.<br>
<font color="#888888"><br>
--<br>
Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>   |   Brisbane, Australia<br>
</font></blockquote></div><br></div>