Last active
May 4, 2022 08:38
-
-
Save guewen/a4a2eba5d128b4ed3129866f80571fbd to your computer and use it in GitHub Desktop.
benchmark odoo recordset union
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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}) | |
>>> 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]
@guewen what version is the second one? seems to be much faster.
@tschanzt what do you call "second one"?
The much faster version is using a set.
Result on a 13.0:
>>> timeit.repeat(code_recordset, setup="records = env['product.product'].browse(range(1,1001))", number=100, globals={'env': env})
[12.858925580978394, 12.715613184031099, 12.757306319021154, 12.897050590021536, 13.071105225011706]
>>> timeit.repeat(code_set, setup="records = env['product.product'].browse(range(1,1001))", number=100, globals={'env': env})
[0.16186794801615179, 0.1302504469640553, 0.13334446505177766, 0.13309406995540485, 0.1337131999898702]
Result on a 14.0, same story:
>>> timeit.repeat(code_recordset, setup="records = env['product.product'].browse(range(1,1001))", number=100, globals={'env': env})
[14.343225489006727, 14.607701032000477, 14.82277410599636, 15.232663155999035, 14.98800701899745]
>>> timeit.repeat(code_set, setup="records = env['product.product'].browse(range(1,1001))", number=100, globals={'env': env})
[0.18435767899791244, 0.14919681400351692, 0.15227286599110812, 0.15313698099635076, 0.16125268299947493]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result on a 12.0: