couchbase/couchbase-python-client — Issue #2: slow crc32
Author: qyloxe
Created: 2011-11-26 09:47:00+00:00
State: open

Please, use fast crc32 from zlib. It is about 18 times faster:

import zlib
import couchbase.crc32 as couch_slow_crc
import time

def Func1(amax=100000):
t1=time.clock()
for i in range(amax):
x=couch_slow_crc.crc32_hash(`i`)
t2=time.clock()
return t2-t1

def Func2(amax=100000):
t1=time.clock()
for i in range(amax):
x=(zlib.crc32(`i`)>>16)&0x7fff
t2=time.clock()
return t2-t1

def Func3(amax=100000):
for i in range(amax):
v1=(zlib.crc32(`i`)>>16)&0x7fff
v2=couch_slow_crc.crc32_hash(`i`)
if v1!=v2:
print 'conflict %d %x %x'%(i,v1,v2)
t2=time.clock()

t1=Func1()
t2=Func2()
print 'time couch',t1
print 'time zlib',t2
print 'speed',t1/t2
Func3()

#######################################
time couch 1.83402449707
time zlib 0.0990188503142
speed 18.5219732531