[Zope-CVS] CVS: Products/ZCTextIndex - Index.py:22.214.171.124
Sun, 5 May 2002 21:14:44 -0400
Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv18382
scaled_int(): Speed the rounding. This function is called in
Index.search()'s innermost loop, and I noticed that it consumed about
0.4 seconds *just* to call scaled_int 55,000 times.
=== Products/ZCTextIndex/Index.py 126.96.36.199 => 188.8.131.52 ===
def scaled_int(f, scale=SCALE_FACTOR):
- return int(round(f * scale))
+ # We expect only positive inputs, so "add a half and chop" is the
+ # same as round(). Surprising, calling round() is significantly more
+ # expensive.
+ return int(f * scale + 0.5)
__implements__ = IIndex