import pytest
from src.core import WordCounter
import tempfile
import random

@pytest.fixture(scope="module")
def large_data():
    """生成1MB测试数据"""
    words = [f"word{i}" for i in range(1000)]
    with tempfile.TemporaryDirectory() as tmpdir:
        data_dir = Path(tmpdir) / "data"
        data_dir.mkdir()
        for i in range(10):
            with open(data_dir / f"bigfile{i}.txt", 'w') as f:
                content = " ".join(random.choices(words, k=100000))
                f.write(content)
        yield str(data_dir)

def test_processing_performance(benchmark, large_data):
    """性能基准测试"""
    counter = WordCounter()
    counter.config = {
        "data_dir": large_data,
        "stop_words_file": "nonexistent",
        "output_file": "/dev/null",
        "top_n": 10,
        "tokenizer": "simple"
    }
    
    # 执行基准测试
    result = benchmark(counter.process_files)
    
    # 验证性能指标
    assert benchmark.stats['mean'] < 1.0  # 平均执行时间 < 1秒