Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
benchmark odoo recordset union
# to run in odoo shell
import timeit
code_recordset = """
result = env['product.product'].browse()
for record in records:
result |= record
"""
code_set = """
result = set()
for record in records:
result.add(record.id)
env['product.product'].browse(result)
"""
timeit.repeat(code_recordset, setup="records = env['product.product'].browse(range(1,1001))", number=100, globals={'env': env})
timeit.repeat(code_set, setup="records = env['product.product'].browse(range(1,1001))", number=100, globals={'env': env})
@guewen

This comment has been minimized.

Copy link
Owner Author

guewen commented Nov 19, 2019

Result on a 12.0:

>>> timeit.repeat(code_recordset, setup="records = env['product.product'].browse(range(1,1001))", number=100, globals={'env': env})
[20.499273910001648, 20.505129003999173, 20.747899630001484]
>>> timeit.repeat(code_set, setup="records = env['product.product'].browse(range(1,1001))", number=100, globals={'env': env})
[0.17951795200133347, 0.18106538800202543, 0.1796633770027256]
@guewen

This comment has been minimized.

Copy link
Owner Author

guewen commented Nov 19, 2019

>>> timeit.repeat(code_recordset, setup="records = env['product.product'].browse(range(1,101))", number=1, globals={'env': env})
[0.005641212999762502, 0.0034032650000881404, 0.0030676499991386663]
>>> timeit.repeat(code_recordset, setup="records = env['product.product'].browse(range(1,1001))", number=1, globals={'env': env})
[0.20266702599838027, 0.20051896199947805, 0.19994786299866973]
>>> timeit.repeat(code_recordset, setup="records = env['product.product'].browse(range(1,5001))", number=1, globals={'env': env})
[4.62678340599814, 4.655581045997678, 4.589156283996999]
>>> timeit.repeat(code_recordset, setup="records = env['product.product'].browse(range(1,10001))", number=1, globals={'env': env})
[18.333455190997483, 18.284903024003142, 18.26011875200129]
@tschanzt

This comment has been minimized.

Copy link

tschanzt commented Dec 4, 2019

@guewen what version is the second one? seems to be much faster.

@guewen

This comment has been minimized.

Copy link
Owner Author

guewen commented Jan 8, 2020

@tschanzt what do you call "second one"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.