run benchmarks on orderedbidict as well as bidict

This commit is contained in:
jab 2016-06-29 23:50:35 -04:00
parent 476bdc77b9
commit 62eabc3473
1 changed files with 23 additions and 17 deletions

View File

@ -1,6 +1,7 @@
from bidict import bidict, orderedbidict, ValueDuplicationError from bidict import bidict, orderedbidict, ValueDuplicationError
import pytest import pytest
bidict_types = (bidict, orderedbidict)
elements = orderedbidict(( elements = orderedbidict((
('H', 'hydrogen'), ('He', 'helium'), ('H', 'hydrogen'), ('He', 'helium'),
@ -35,40 +36,45 @@ update_nodup = orderedbidict((
('Cn', 'copernicium'), ('Cn', 'copernicium'),
)) ))
update_withdupval = bidict(update_nodup, key_with_dup_val='hydrogen') update_withdupval = orderedbidict(update_nodup, key_with_dup_val='hydrogen')
def test_put_nodup(benchmark): @pytest.mark.parametrize('B', bidict_types)
elements_ = bidict(elements) def test_put_nodup(B, benchmark):
benchmark(elements_.put, 'K', 'potassium') b = B(elements)
benchmark(b.put, 'K', 'potassium')
def test_put_withdup(benchmark): @pytest.mark.parametrize('B', bidict_types)
elements_ = bidict(elements) def test_put_withdup(B, benchmark):
b = B(elements)
def runner(): def runner():
with pytest.raises(ValueDuplicationError): with pytest.raises(ValueDuplicationError):
elements_.put('key_with_dup_val', 'hydrogen') b.put('key_with_dup_val', 'hydrogen')
benchmark(runner) benchmark(runner)
def test_update_nodup(benchmark): @pytest.mark.parametrize('B', bidict_types)
elements_ = bidict(elements) def test_update_nodup(B, benchmark):
benchmark(elements_.update, update_nodup) b = B(elements)
benchmark(b.update, update_nodup)
def test_update_withdup(benchmark): @pytest.mark.parametrize('B', bidict_types)
elements_ = bidict(elements) def test_update_withdup(B, benchmark):
b = B(elements)
def runner(): def runner():
with pytest.raises(ValueDuplicationError): with pytest.raises(ValueDuplicationError):
elements_.update(update_withdupval) b.update(update_withdupval)
benchmark(runner) benchmark(runner)
def test_forceupdate_withdup(benchmark): @pytest.mark.parametrize('B', bidict_types)
elements_ = bidict(elements) def test_forceupdate_withdup(B, benchmark):
benchmark(elements_.forceupdate, update_withdupval) b = B(elements)
assert elements_.inv['hydrogen'] == 'key_with_dup_val' benchmark(b.forceupdate, update_withdupval)
assert b.inv['hydrogen'] == 'key_with_dup_val'