From bd02ffc23e5c435751b9395d05a144f802e54233 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Thu, 16 Nov 2023 16:16:23 -0500 Subject: [PATCH] perf: parallelize checksum generation for contig --- fasta_checksum_utils/_contig.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fasta_checksum_utils/_contig.py b/fasta_checksum_utils/_contig.py index d907972..e214a8a 100644 --- a/fasta_checksum_utils/_contig.py +++ b/fasta_checksum_utils/_contig.py @@ -1,3 +1,4 @@ +import asyncio import pysam from typing import Generator from .algorithms import ChecksumAlgorithm @@ -23,8 +24,4 @@ def gen_sequence() -> Generator[bytes, None, None]: .encode("ascii") ) - r = [] - for a in algorithms: - r.append(await a.checksum_sequence(gen_sequence())) - - return tuple(r) + return tuple(await asyncio.gather(*(a.checksum_sequence(gen_sequence()) for a in algorithms)))