From 03d8be3790f38c5aef3e48908ce94a00ec169a99 Mon Sep 17 00:00:00 2001 From: "mra (Open ERP)" Date: Tue, 22 Sep 2009 19:44:47 +0530 Subject: [PATCH] [FIX] base_module_quality: speed test if read method has exception bzr revid: mra@tinyerp.com-20090922141447-e22fbytnhwtokuqs --- .../speed_test/speed_test.py | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/addons/base_module_quality/speed_test/speed_test.py b/addons/base_module_quality/speed_test/speed_test.py index 875b2de136a..29252cab8b1 100644 --- a/addons/base_module_quality/speed_test/speed_test.py +++ b/addons/base_module_quality/speed_test/speed_test.py @@ -64,6 +64,9 @@ This test checks the speed of the module. Note that at least 5 demo data is need result_dict2 = {} self.result_details += _("O(1) means that the number of SQL requests to read the object does not depand on the number of objects we are reading. This feature is hardly wished.\n") for obj, ids in obj_ids.items(): + code_base_complexity = 0 + code_half_complexity = 0 + code_size_complexity = 0 obj_counter += 1 ids = ids[:100] size = len(ids) @@ -71,34 +74,38 @@ This test checks the speed of the module. Note that at least 5 demo data is need if size: speed_list = [] #we perform the operation twice, and count the number of queries in the second run. This allows to avoid the cache effect. (like translated terms that asks for more queries) - pool.get(obj).read(cr, uid, [ids[0]]) - cnt = cr.count - pool.get(obj).read(cr, uid, [ids[0]]) - code_base_complexity = cr.count - cnt + try: + pool.get(obj).read(cr, uid, [ids[0]]) + cnt = cr.count + pool.get(obj).read(cr, uid, [ids[0]]) + code_base_complexity = cr.count - cnt - pool.get(obj).read(cr, uid, ids[:size/2]) - cnt = cr.count - pool.get(obj).read(cr, uid, ids[:size/2]) - code_half_complexity = cr.count - cnt + pool.get(obj).read(cr, uid, ids[:size/2]) + cnt = cr.count + pool.get(obj).read(cr, uid, ids[:size/2]) + code_half_complexity = cr.count - cnt - pool.get(obj).read(cr, uid, ids) - cnt = cr.count - pool.get(obj).read(cr, uid, ids) - code_size_complexity = cr.count - cnt - - if size < 5: - speed_list = [obj, size, code_base_complexity, code_half_complexity, code_size_complexity, _("Warning! Not enough demo data")] - list2 = [obj, _("No enough data")] + pool.get(obj).read(cr, uid, ids) + cnt = cr.count + pool.get(obj).read(cr, uid, ids) + code_size_complexity = cr.count - cnt + except Exception, e: + list2 = [obj, _("Error in Read method")] + speed_list = [obj, size, code_base_complexity, code_half_complexity, code_size_complexity, _("Error in Read method:" + str(e))] else: - if code_size_complexity <= (code_base_complexity + size): - complexity = _("O(1)") - score += 1 - list2 = [obj, _("Efficient")] + if size < 5: + speed_list = [obj, size, code_base_complexity, code_half_complexity, code_size_complexity, _("Warning! Not enough demo data")] + list2 = [obj, _("No enough data")] else: - complexity = _("O(n) or worst") - list2 = [obj, _("Not Efficient")] + if code_size_complexity <= (code_base_complexity + size): + complexity = _("O(1)") + score += 1 + list2 = [obj, _("Efficient")] + else: + complexity = _("O(n) or worst") + list2 = [obj, _("Not Efficient")] - speed_list = [obj, size, code_base_complexity, code_half_complexity, code_size_complexity, complexity] + speed_list = [obj, size, code_base_complexity, code_half_complexity, code_size_complexity, complexity] else: speed_list = [obj, size, "", "", "", _("Warning! Object has no demo data")] list2 = [obj, _("No data")]