codon icon indicating copy to clipboard operation
codon copied to clipboard

the code slow than python3.8

Open novvoo opened this issue 2 years ago • 2 comments

import time

def test(n, m):
    vals = []
    keys = []
    for i in range(m):
        vals.append(i)
        keys.append(f'a{i}') 
    d = None
    for i in range(n):
        d = dict(zip(keys, vals))
    return d

if __name__ == '__main__':
    st = time.time()
    print(test(1000000, 100))
    print('use:', time.time() - st)

$ python3 test3.py 
{'a0': 0, 'a1': 1, 'a2': 2, 'a3': 3, 'a4': 4, 'a5': 5, 'a6': 6, 'a7': 7, 'a8': 8, 'a9': 9, 'a10': 10, 'a11': 11, 'a12': 12, 'a13': 13, 'a14': 14, 'a15': 15, 'a16': 16, 'a17': 17, 'a18': 18, 'a19': 19, 'a20': 20, 'a21': 21, 'a22': 22, 'a23': 23, 'a24': 24, 'a25': 25, 'a26': 26, 'a27': 27, 'a28': 28, 'a29': 29, 'a30': 30, 'a31': 31, 'a32': 32, 'a33': 33, 'a34': 34, 'a35': 35, 'a36': 36, 'a37': 37, 'a38': 38, 'a39': 39, 'a40': 40, 'a41': 41, 'a42': 42, 'a43': 43, 'a44': 44, 'a45': 45, 'a46': 46, 'a47': 47, 'a48': 48, 'a49': 49, 'a50': 50, 'a51': 51, 'a52': 52, 'a53': 53, 'a54': 54, 'a55': 55, 'a56': 56, 'a57': 57, 'a58': 58, 'a59': 59, 'a60': 60, 'a61': 61, 'a62': 62, 'a63': 63, 'a64': 64, 'a65': 65, 'a66': 66, 'a67': 67, 'a68': 68, 'a69': 69, 'a70': 70, 'a71': 71, 'a72': 72, 'a73': 73, 'a74': 74, 'a75': 75, 'a76': 76, 'a77': 77, 'a78': 78, 'a79': 79, 'a80': 80, 'a81': 81, 'a82': 82, 'a83': 83, 'a84': 84, 'a85': 85, 'a86': 86, 'a87': 87, 'a88': 88, 'a89': 89, 'a90': 90, 'a91': 91, 'a92': 92, 'a93': 93, 'a94': 94, 'a95': 95, 'a96': 96, 'a97': 97, 'a98': 98, 'a99': 99}
use: 5.197545051574707
~$ ./test3 
{'a76': 76, 'a77': 77, 'a78': 78, 'a79': 79, 'a80': 80, 'a81': 81, 'a82': 82, 'a83': 83, 'a84': 84, 'a85': 85, 'a86': 86, 'a87': 87, 'a88': 88, 'a89': 89, 'a90': 90, 'a91': 91, 'a92': 92, 'a93': 93, 'a94': 94, 'a95': 95, 'a96': 96, 'a97': 97, 'a10': 10, 'a11': 11, 'a12': 12, 'a13': 13, 'a14': 14, 'a15': 15, 'a16': 16, 'a17': 17, 'a18': 18, 'a19': 19, 'a98': 98, 'a99': 99, 'a20': 20, 'a21': 21, 'a22': 22, 'a23': 23, 'a24': 24, 'a25': 25, 'a26': 26, 'a27': 27, 'a28': 28, 'a29': 29, 'a30': 30, 'a31': 31, 'a32': 32, 'a33': 33, 'a34': 34, 'a35': 35, 'a36': 36, 'a37': 37, 'a38': 38, 'a39': 39, 'a40': 40, 'a41': 41, 'a42': 42, 'a43': 43, 'a44': 44, 'a45': 45, 'a46': 46, 'a47': 47, 'a48': 48, 'a49': 49, 'a50': 50, 'a51': 51, 'a52': 52, 'a53': 53, 'a54': 54, 'a55': 55, 'a56': 56, 'a57': 57, 'a58': 58, 'a59': 59, 'a60': 60, 'a61': 61, 'a62': 62, 'a63': 63, 'a64': 64, 'a65': 65, 'a66': 66, 'a67': 67, 'a68': 68, 'a69': 69, 'a0': 0, 'a1': 1, 'a2': 2, 'a3': 3, 'a4': 4, 'a5': 5, 'a6': 6, 'a7': 7, 'a8': 8, 'a9': 9, 'a70': 70, 'a71': 71, 'a72': 72, 'a73': 73, 'a74': 74, 'a75': 75}
use: 42.3717

novvoo avatar Mar 17 '23 04:03 novvoo

Thanks for the report -- it seems like the Codon version wasn't built with -release (can you confirm?). However when testing with -release, Codon is still a bit slower here somehow. I'll investigate this further...

arshajii avatar Mar 17 '23 13:03 arshajii

Quick update: this seems to be a GC-related issue; with GC turned off and using -release, the Codon version is slightly faster (probably wouldn't expect a massive speed difference here since most time is spent inserting keys into the dict).

arshajii avatar Mar 17 '23 14:03 arshajii

After conducting manual tests with various n and m values, it was found that Codon is at most 1.4 times slower than Python when m falls within the range of 100 to 128. However, for other values of m, Codon tends to be approximately twice as fast as Python. In order to understand why this is happening and identify any underlying patterns or causes, we need to conduct additional analysis and investigation.

elisbyberi avatar Mar 28 '23 01:03 elisbyberi