trunk r61823 now compiles binascii to use zlib&#39;s crc32 rather than its own if the zlib library is available at compile time (that should shave a kilobyte off binascii.so on most systems).<br><br>{binascii,zlib}.crc32, zlib.adler32 and binascii.crc_hqx could all potentially live in the hashlib module but their APIs are a notably different as they return a number rather than a string (leaving serialization byte order up to the user and are functions that allow passing in the start value rather than objects that maintain an internal state to be retrieved when done adding data.&nbsp; It&#39;d be easy enough to wrap them to have the same API in python but that&#39;d destroy any speed benefit.<br>
<br>The hashlib documentation and docstring mention that people should look at zlib if they want crc32 or adler32.&nbsp; IMHO thats enough even if zlib (or binascii) is a &quot;weird&quot; place in an overly logical sense.&nbsp; They&#39;re not really the same class of hash function.<br>
<br>-g<br><br><div class="gmail_quote">On Thu, Mar 20, 2008 at 12:02 AM, Guido van Rossum &lt;<a href="mailto:guido@python.org">guido@python.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hm. &nbsp;zlib is an odd place to find this API (unless you know way more<br>
about gzip than healthy :-). &nbsp;Though binascii isn&#39;t much better. &nbsp;I&#39;d<br>
rather expect this in the vicinity of md5 and sha... Is it possible to<br>
tweak that C code to use the zlib version if present and the old C<br>
code otherwise?<br>
<div><div></div><div class="Wj3C7c"><br>
On Tue, Mar 18, 2008 at 3:21 PM, Gregory P. Smith &lt;<a href="mailto:greg@krypto.org">greg@krypto.org</a>&gt; wrote:<br>
&gt; Both modules have a crc32 function. &nbsp;The zlib version is faster when zlib<br>
&gt; has been compiled optimally or about the same when zlib is old or uses its C<br>
&gt; code.<br>
&gt;<br>
&gt; Should we ditch the binascii.crc32 version in py3k?<br>
&gt;<br>
&gt; &nbsp;64bit Linux (CentOS 5.1):<br>
&gt;<br>
&gt; $ python2.4 -m timeit &#39;foo=&quot;abcdefghijklmnop&quot;*10&#39; &#39;import binascii as mod&#39;<br>
&gt; &#39;f = mod.crc32&#39; &#39;for x in xrange(100000): f(foo)&#39;<br>
&gt; &nbsp;10 loops, best of 3: 108 msec per loop<br>
&gt; $ python2.4 -m timeit &#39;foo=&quot;abcdefghijklmnop&quot;*10&#39; &#39;import zlib as mod&#39; &#39;f =<br>
&gt; mod.crc32&#39; &#39;for x in xrange(100000): f(foo)&#39;<br>
&gt; &nbsp;10 loops, best of 3: 40.5 msec per loop<br>
&gt;<br>
&gt; 32bit MacOS X 10.4:<br>
&gt;<br>
&gt; % python2.3 /usr/lib/python2.3/timeit.py &#39;foo=&quot;abcdefghijklmnop&quot;*10&#39; &#39;import<br>
&gt; binascii as mod&#39; &#39;f = mod.crc32&#39; &#39;for x in xrange(100000): f(foo)&#39;<br>
&gt; &nbsp;10 loops, best of 3: 7.37e+04 usec per loop<br>
&gt; % python2.3 /usr/lib/python2.3/timeit.py &#39;foo=&quot;abcdefghijklmnop&quot;*10&#39; &#39;import<br>
&gt; zlib as mod&#39; &#39;f = mod.crc32&#39; &#39;for x in xrange(100000): f(foo)&#39;<br>
&gt; &nbsp;10 loops, best of 3: 4.62e+04 usec per loop<br>
&gt;<br>
&gt; Removal from binascii would break things for platforms or embedded systems<br>
&gt; wanting crc32 that don&#39;t want to include zlib. &nbsp;Anyone care?<br>
&gt;<br>
&gt; What about 2.x? &nbsp;if we remove the redundancy in py3k i guess we deprecate<br>
&gt; binascii.crc32 and remove in 2.7?<br>
&gt;<br>
&gt; -gps<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; &nbsp;Python-3000 mailing list<br>
&gt; &nbsp;<a href="mailto:Python-3000@python.org">Python-3000@python.org</a><br>
&gt; &nbsp;<a href="http://mail.python.org/mailman/listinfo/python-3000" target="_blank">http://mail.python.org/mailman/listinfo/python-3000</a><br>
&gt; &nbsp;Unsubscribe:<br>
&gt; <a href="http://mail.python.org/mailman/options/python-3000/guido%40python.org" target="_blank">http://mail.python.org/mailman/options/python-3000/guido%40python.org</a><br>
&gt;<br>
&gt;<br>
<font color="#888888"><br>
<br>
<br>
--<br>
--Guido van Rossum (home page: <a href="http://www.python.org/%7Eguido/" target="_blank">http://www.python.org/~guido/</a>)<br>
</font></blockquote></div><br>