Skip to content

Commit

Permalink
Fixes an invalidation order issue in the benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Nov 23, 2014
1 parent 3eb8dcd commit dc061ee
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ def __init__(self, n=20):
self.n = n
self.data = []

def bench_once(self, context, num_queries, invalidate_after=False):
def bench_once(self, context, num_queries, invalidate_before=False):
for _ in range(self.n):
if invalidate_before:
clear(db_alias=self.db_alias)
with AssertNumQueries(num_queries, using=self.db_alias):
start = time()
self.query_function(self.db_alias)
Expand All @@ -60,8 +62,6 @@ def bench_once(self, context, num_queries, invalidate_after=False):
'context': context,
'db': self.db_vendor,
'cache': self.cache_name})
if invalidate_after:
clear(db_alias=self.db_alias)

def benchmark(self, query_str, to_list=True, num_queries=1):
self.query_name = query_str
Expand All @@ -73,9 +73,7 @@ def benchmark(self, query_str, to_list=True, num_queries=1):
with cachalot_settings(CACHALOT_ENABLED=False):
self.bench_once(CONTEXTS[0], num_queries)

self.bench_once(CONTEXTS[1], num_queries, invalidate_after=True)

self.query_function(self.db_alias)
self.bench_once(CONTEXTS[1], num_queries, invalidate_before=True)

self.bench_once(CONTEXTS[2], 0)

Expand Down

0 comments on commit dc061ee

Please sign in to comment.