On 7/19/07, <b class="gmail_sendername">Eric Brunson</b> &lt;<a href="mailto:brunson@brunson.com">brunson@brunson.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Tino Dai wrote:<br>&gt; On 7/19/07, *Kent Johnson* &lt;<a href="mailto:kent37@tds.net">kent37@tds.net</a> &lt;mailto:<a href="mailto:kent37@tds.net">kent37@tds.net</a>&gt;&gt;<br>&gt; wrote:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; The two advantages that I can see are, I don&#39;t need to type as
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; much, and<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; there would be a speed up in the execution of code.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Why do you expect a speedup?<br>&gt;<br>&gt;<br>&gt; In the&nbsp;&nbsp;Python&nbsp;&nbsp;Reference by David Beazley on p. 40, he substituted
<br>&gt; import math<br>&gt; with from math import sqrt and he switched out d = d + math.sqrt(i) with<br>&gt; sqrt(i). He said that that change made the program run twice as fast.<br>&gt; So therefore<br>&gt; I was under the impression that &quot;from somemodule import someclass&quot;
<br>&gt; would always be<br>&gt; faster than import somemodule.<br><br>The reason it&#39;s faster is because to get the actual function for<br>math.sqrt() after importing math, you have to do a dictionary lookup in<br>the &quot;math&quot; namespace.&nbsp;&nbsp;I don&#39;t think it should run twice as fast.&nbsp;&nbsp;I
<br>would only worry about it if you had some situation where you were using<br>the same name over and over:<br><br>import math<br>for i in range( 0, 1000000000 ):<br>&nbsp;&nbsp;&nbsp;&nbsp;x = math.sqrt(i)<br><br>That&#39;s 1000000000 dictionary lookups.&nbsp;&nbsp;Importing just the sqrt name
<br>would avoid those lookups, so would:<br><br>import math<br>f = math.sqrt<br>for i in range( 0, 1000000000 ):<br>&nbsp;&nbsp; x = f(i)<br><br>Does that make sense?</blockquote><div><br>I guess there is no silver bullet. Thanks for that!&nbsp; It makes total sense
<br>now that you mention it.<br><br>-Tino<br>&nbsp;<br></div><br></div><br>