Message47135
Logged In: YES
user_id=80475
Nice simplification.
Checked in with minor modifications:
* reduce() replaced with clearer, faster for-loop (see
timings below)
* chain of ifs covered distinct cases, so used if-elif-else
to avoid unnecessary tests.
See Lib/decimal.py 1.30
----- Timing of for-loop vs reduce() with lambda --------
>>> min(Timer(s1, setup).repeat(9, 1000))
0.039173469216714996
>>> min(Timer(s1, setup).repeat(9, 100000))
3.8988694078010013
>>> min(Timer(s2, setup).repeat(9, 100000))
2.2458371746090293
>>> s1
'cum = reduce(lambda x,y: 10*x+y, val)'
>>> s2
'\ncum = 0\nfor dig in val:\n cum = cum * 10 + dig\n'
>>> setup
'\nval = [9,6,1,2,3,0,2,4,1,5,7,1,5,6,9]\n' |
|
Date |
User |
Action |
Args |
2007-08-23 15:40:20 | admin | link | issue1053375 messages |
2007-08-23 15:40:20 | admin | create | |
|