loading...

Discussion on: Speed up your Odoo 12.0 code

Collapse
opencode profile image
Apruzzese Francesco Author

It'a a simple example to filter recordset. Of course, there is a better way to write this but my focus is on "Odoo code" and not "Pure Python Code" ;)

Thank you :)

Collapse
hanpari profile image
Pavel Morava

I know 😄 and but still noteworthy.

WORDS = ("Ahaha asa sas s sas aa AA A sd df df fdfdf  sdfs ds fsf fsf sfs fsdfs fsfsf sfsf sf" 
         "SAS D DA A SDAD ADD ADAD ADAD ADA DASDSDAFDEAA AD AD D  SD  ad sds saAA   AADADDdas  a a AA SAD"*1000).split()

%%timeit
res1 = " ".join(filter(lambda r: r.lower().startswith('a'), WORDS))
12.8 ms ± 107 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
def my_filter(name, lower="a", upper="A"):
    first = name[0]
    return first is lower or first is upper
%%timeit 
res2 = " ".join(filter(my_filter, WORDS))

6.08 ms ± 26.6 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
6/13
0.46153846153846156