例如我有一个代码。
def my_function(my_dict, selections_list):
for value in selections:
if value in my_dict: # maybe try -> except KeyError ?!
a = my_dict[value]
# Do something
if my_dict[value]:
....
# use my_dict[value] multiple times as right value.
# ....
# Very complicated code
如果my_function被调用了数百万次,是否有任何主要原因可以链接my_dict [value]并在pypy中使用链接对象。
def my_function(my_dict, selections_list):
for value in selections:
if value in my_dict: # maybe try -> except KeyError ?!
a = my_dict[value]
# Do something
if a:
# use a multiple times instead if my_dict[value]
# ....
# Very complicated code
我想了解PyPy是否如此聪明。
答案 0 :(得分:0)
我试过两次跑两次并计时。结果:没有重大区别。我猜PyPy并不那么聪明。