Message132969
| Author |
gruszczy |
| Recipients |
daniel.urban, eric.smith, gruszczy, ncoghlan, rhettinger, stutzbach, terry.reedy |
| Date |
2011年04月04日.21:07:17 |
| SpamBayes Score |
0.003927866 |
| Marked as misclassified |
No |
| Message-id |
<1301951238.42.0.370079186754.issue11707@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Here are some example performance results:
def cmp(x, y):
return y - x
sorted(range(1, 10000000), key=cmp_to_key(cmp))
'''
C version:
real 0m19.994s
user 0m8.053s
sys 0m1.044s
Python version:
real 0m28.825s
user 0m28.046s
sys 0m0.728s
'''
def cmp(x, y):
x = int(x)
y = int(y)
return (x > y) - (y > x)
sorted([str(i) for i in reversed(range(1, 2000000))], key=cmp_to_key(cmp))
'''
Python version
real 0m15.930s
user 0m15.629s
sys 0m0.284s
C version
real 0m10.880s
user 0m10.585s
sys 0m0.284s
'''
There is some performance gain. I don't know however, if it's enough to use C version instead of Python, that's for Raymond to decide. |
|