Skip to content

Commit

Permalink
leave Python changes for another PR
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Jul 24, 2024
1 parent e3d42f3 commit 07c37f7
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 207 deletions.
124 changes: 124 additions & 0 deletions benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,74 @@ def load_sequences():
return sequences


class TimeMinHashSuite:
def setup(self):
self.mh = MinHash(MINHASH_NUM, MINHASH_K, track_abundance=False)
self.protein_mh = MinHash(
MINHASH_NUM, MINHASH_K, is_protein=True, track_abundance=False
)
self.sequences = load_sequences()

self.populated_mh = MinHash(MINHASH_NUM, MINHASH_K, track_abundance=False)
for seq in self.sequences:
self.populated_mh.add_sequence(seq)

def time_add_sequence(self):
mh = self.mh
sequences = self.sequences
for seq in sequences:
mh.add_sequence(seq)

def time_add_protein(self):
mh = self.protein_mh
sequences = self.sequences
for seq in sequences:
mh.add_protein(seq)

def time_get_mins(self):
mh = self.populated_mh
for i in range(GET_MINS_RANGE):
mh.get_mins()

def time_add_hash(self):
mh = self.mh
for i in range(ADD_HASH_RANGE):
mh.add_hash(i)

def time_add_many(self):
mh = self.mh
mh.add_many(list(range(ADD_MANY_RANGE)))

def time_similarity(self):
mh = self.mh
other_mh = self.populated_mh
for i in range(SIMILARITY_TIMES):
mh.similarity(other_mh)

def time_count_common(self):
mh = self.mh
other_mh = self.populated_mh
for i in range(COUNT_COMMON_TIMES):
mh.count_common(other_mh)

def time_merge(self):
mh = self.mh
other_mh = self.populated_mh
for i in range(MERGE_TIMES):
mh.merge(other_mh)

def time_copy(self):
mh = self.populated_mh
for i in range(COPY_TIMES):
mh.__copy__()

def time_concat(self):
mh = self.mh
other_mh = self.populated_mh
for i in range(CONCAT_TIMES):
mh += other_mh


class PeakmemMinHashSuite:
def setup(self):
self.mh = MinHash(MINHASH_NUM, MINHASH_K, track_abundance=True)
Expand Down Expand Up @@ -66,6 +134,33 @@ def peakmem_add_many(self):
####################


class TimeMinAbundanceSuite(TimeMinHashSuite):
def setup(self):
TimeMinHashSuite.setup(self)
self.mh = MinHash(MINHASH_NUM, MINHASH_K, track_abundance=True)

self.populated_mh = MinHash(MINHASH_NUM, MINHASH_K, track_abundance=True)
for seq in self.sequences:
self.populated_mh.add_sequence(seq)

def time_get_mins_abundance(self):
mh = self.populated_mh
for i in range(GET_MINS_RANGE):
mh.get_mins(with_abundance=True)

def time_set_abundances(self):
mh = self.mh
mins = self.populated_mh.get_mins(with_abundance=True)
for i in range(SET_ABUNDANCES_RANGE):
mh.set_abundances(mins)

def time_set_abundances_noclear(self):
mh = self.mh
mins = self.populated_mh.get_mins(with_abundance=True)
for i in range(SET_ABUNDANCES_RANGE):
mh.set_abundances(mins, clear=False)


class PeakmemMinAbundanceSuite(PeakmemMinHashSuite):
def setup(self):
PeakmemMinHashSuite.setup(self)
Expand All @@ -75,6 +170,35 @@ def setup(self):
####################


class TimeZipStorageSuite:
def setup(self):
import zipfile

self.zipfile = NamedTemporaryFile()

with zipfile.ZipFile(
self.zipfile, mode="w", compression=zipfile.ZIP_STORED
) as storage:
for i in range(ZIP_STORAGE_WRITE):
# just so we have lots of entries
storage.writestr(str(i), b"0")
# one big-ish entry
storage.writestr("sig1", b"9" * 1_000_000)

def time_load_from_zipstorage(self):
with ZipStorage(self.zipfile.name) as storage:
for i in range(ZIP_STORAGE_LOAD):
storage.load("sig1")

def time_load_small_from_zipstorage(self):
with ZipStorage(self.zipfile.name) as storage:
for i in range(ZIP_STORAGE_LOAD):
storage.load("99999")

def teardown(self):
self.zipfile.close()


class PeakmemZipStorageSuite:
def setup(self):
import zipfile
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ test = [
"pytest>=6.2.4,<8.4.0",
"pytest-cov>=4,<6.0",
"pytest-xdist>=3.1",
"pytest-benchmark>=4.0",
"pyyaml>=6,<7",
"diff-cover>=7.3",
"covdefaults>=2.2.2",
Expand Down
176 changes: 0 additions & 176 deletions tests/test_benchmarks.py

This file was deleted.

32 changes: 2 additions & 30 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -111,34 +111,6 @@ commands =
asv machine --yes
asv continuous latest HEAD {posargs}

[testenv:benchmarks]
description = run pytest-benchmark for benchmarking
changedir = {toxinidir}
commands =
pytest \
--cov "{envsitepackagesdir}/sourmash" \
--cov-config "{toxinidir}/tox.ini" \
--cov-report= \
--junitxml {toxworkdir}/junit.benchmarks.xml \
--benchmark-only \
-n 0 \
{posargs:tests}

[testenv:codspeed]
description = run codspeed for benchmarking
deps =
pytest-codspeed
changedir = {toxinidir}
commands =
pytest \
--cov "{envsitepackagesdir}/sourmash" \
--cov-config "{toxinidir}/tox.ini" \
--cov-report= \
--junitxml {toxworkdir}/junit.codspeed.xml \
--codspeed \
-k benchmarks \
{posargs:tests}

[testenv:docs]
description = invoke sphinx-build to build the HTML docs
basepython = python3.10
Expand Down Expand Up @@ -208,7 +180,7 @@ commands =
coverage xml -i -o {toxworkdir}/coverage.xml
coverage html -i -d {toxworkdir}/htmlcov
diff-cover --compare-branch {env:DIFF_AGAINST:origin/latest} {toxworkdir}/coverage.xml
depends = py312, py311, py310, pypy3, codspeed
depends = py312, py311, py310, pypy3
pass_env = {[testenv]pass_env}
DIFF_AGAINST
set_env = COVERAGE_FILE={toxworkdir}/.coverage
Expand Down Expand Up @@ -261,7 +233,7 @@ source = src/sourmash/
python =
3.10: py310, docs, package_description, coverage
3.11: py311, coverage
3.12: py312, coverage, codspeed
3.12: py312, coverage
[flake8]
max-complexity = 22
Expand Down

0 comments on commit 07c37f7

Please sign in to comment.