Skip to content

Commit

Permalink
Benchmark inclusion and exclusion filter classes
Browse files Browse the repository at this point in the history
Don't run benchmarks in CI as they give very different results for
different runs, even with `--benchmark-timer=time.process_time`.
  • Loading branch information
twaugh committed Oct 26, 2015
1 parent 8f01a4a commit 5d1e671
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ install:
- pip install PyYAML
- pip install flexmock
- pip install pytest-cov coveralls
script: py.test -vv tests --cov journal_brief
- pip install -r tests/requirements.txt
script: py.test -vv tests --cov journal_brief --benchmark-skip
sudo: false
notifications:
email: false
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest-benchmark
38 changes: 38 additions & 0 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,44 @@
logging.basicConfig(level=logging.DEBUG)


class TestFilterProfile(object):
def test_inclusion(self, benchmark):
matches = ['never matched {0}'.format(n) for n in range(100)]
rule = {'MESSAGE': matches}
for x in range(100):
rule['FIELD{0}'.format(x)] = 'never matched'

inclusion = Inclusion(rule)

entry = {
'MESSAGE': 'message',
'__CURSOR': '1',
}

for x in range(100):
entry['FIELD{0}'.format(x)] = x

assert not benchmark(inclusion.matches, entry)

def test_exclusion(self, benchmark):
matches = ['never matched {0}'.format(n) for n in range(100)]
rule = {'MESSAGE': matches}
for x in range(100):
rule['FIELD{0}'.format(x)] = '/never matched/'

exclusion = Exclusion(rule)

entry = {
'MESSAGE': 'message',
'__CURSOR': '1',
}

for x in range(100):
entry['FIELD{0}'.format(x)] = x

assert not benchmark(exclusion.matches, entry)


class TestInclusion(object):
def test_and(self):
inclusion = Inclusion({'MESSAGE': ['include this'],
Expand Down

0 comments on commit 5d1e671

Please sign in to comment.