File size: 1,718 Bytes
b31f748 73ab668 b31f748 73ab668 b31f748 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# -*- coding: utf-8 -*-
from loguru import logger as log
from pathlib import Path
import iscc_sct as sct
import argparse
import time
def benchmark(folder):
"""
Benchmark Text-Code generation for all text files in `folder`.
Per file stats are logged to the console during processing.
Comprehensive aggregated statistics are shown after processing all images
:param folder: Folder containing text files for benchmarking
"""
folder = Path(folder)
assert folder.is_dir(), f"{folder} is not a directory."
total_time = 0
file_count = 0
for txt_path in folder.glob("*.txt"):
start_time = time.time()
try:
iscc_meta = sct.code_text_semantic(txt_path)
except Exception as e:
log.error(f"Processing {txt_path.name} failed: {e}")
continue
end_time = time.time()
elapsed_time = end_time - start_time
total_time += elapsed_time
file_count += 1
log.info(
f"Processed {txt_path.name} in {elapsed_time:.2f} seconds. ISCC: {iscc_meta['iscc']}"
)
if file_count > 0:
avg_time = total_time / file_count
log.info(
f"Processed {file_count} files in {total_time:.2f} seconds. Average time per file: {avg_time:.2f} seconds."
)
else:
log.warning("No text files found in the provided folder.")
def main():
parser = argparse.ArgumentParser(description="Benchmark ISCC Semantic-Code Text generation.")
parser.add_argument(
"folder", type=str, help="Directory containing text files for benchmarking."
)
args = parser.parse_args()
benchmark(args.folder)
if __name__ == "__main__":
main()
|