Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95580
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-08-22 23:10 -0700 |
| Message-ID | <2aa39ddd-bb07-4a09-a046-a011e215882a@googlegroups.com> (permalink) |
| Subject | how to handle cpu cache in python ( or fastest way to call a function once) |
| From | Yuzhi Xu <yuzhixu.ruc@gmail.com> |
I find out that python's VM seems to be very unfriendly with CPU-Cache.
see:
http://stackoverflow.com/questions/32163585/how-to-handle-cpu-cache-in-python-or-fastest-way-to-call-a-function-once
http://stackoverflow.com/questions/32153178/python-functionor-a-code-block-runs-much-slower-with-a-time-interval-in-a-loop
for example:
*******************************************
import time
a = range(500)
sum(a)
for i in range(1000000): #just to create a time interval, seems this disturb cpu cache?
pass
st = time.time()
sum(a)
print (time.time() - st)*1e6
*********************************************
time:> 100us
another case:
*********************************************
import time
a = range(500)
for i in range(100000):
st = time.time()
sum(a)
print (time.time() - st)*1e6
*********************************************
time:~ 20us
we can see when running frequently, the code becomes much faster.
is there a solution?
I feel this question is very difficult. one must has indepth unstanding about the mechanism of python virtual machine, c and cpu-cache.
Do you have any suggestion about where to post this question for a possible answer?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
how to handle cpu cache in python ( or fastest way to call a function once) Yuzhi Xu <yuzhixu.ruc@gmail.com> - 2015-08-22 23:10 -0700
Re: how to handle cpu cache in python ( or fastest way to call a function once) Stefan Behnel <stefan_ml@behnel.de> - 2015-08-23 11:54 +0200
Re: how to handle cpu cache in python ( or fastest way to call a function once) Steven D'Aprano <steve@pearwood.info> - 2015-08-23 21:59 +1000
Re: how to handle cpu cache in python ( or fastest way to call a function once) Vladimir Ignatov <kmisoft@gmail.com> - 2015-08-23 08:07 -0400
Re: how to handle cpu cache in python ( or fastest way to call a function once) Steven D'Aprano <steve@pearwood.info> - 2015-08-23 22:42 +1000
csiph-web