减少循环执行时间python

时间:2019-10-25 20:18:14

标签: python python-3.x

我正在为prefetcher编写代码,但是由于循环如此之多,我在执行中花费了很多时间。我的输入列表在prefetcher中,它的长度为1000,如何才能减少我的时间。预先谢谢你

def pairwise(iterable):
    a=iter(iterable)
    return itertools.zip_longest(a,a)

stride=0
newaddr=0
confidence=0
sub1=0
sub2=0
minimum=0
prefetchB=[]
for x,y in pairwise(prefetch):
    stride=abs(x-y)
    newaddr=x+stride
    prefetchBuf.append([x,stride,newaddr,confidence])
    for x in range(0,len(prefetchBuf)):
        for y in range(1,len(prefetchBuf)-1):
            for z in range(2,len(prefetchBuf)-2):
                if prefetchBuf[x][2]==prefetchBuf[y][0]:
                    if prefetchBuf[y][1]==0:
                        confidence+=1
                        prefetchBuf[x][-1]=confidence
                        if prefetchBuf[x][-1]==confiuser:
                            cacheArray[index]=prefetchBuf[x][2]
                    else:
                        stride=abs(z-y)
                        newaddr=y+stride
                        prefetchBuf[y][1]=stride
                        prefetchBuf[y][2]=newaddr
                else:
                    stride=abs(z-y)
                    newaddr=y+stride
                    prefetchBuf[y][1]=stride
                    prefetchBuf[y][2]=newaddr

0 个答案:

没有答案