def test_cache_page_performance(temp_dir: str):
    """Test that using cache pages improves performance when retrieving many events."""
    file_store = get_file_store('local', temp_dir)

    # Create an event stream with cache enabled
    cached_stream = EventStream('perf_test_cached', file_store)
    cached_stream.cache_size = 10

    # Add a significant number of events to the cached stream
    num_events = 50
    for i in range(num_events):
        cached_stream.add_event(NullObservation(f'test{i}'), EventSource.AGENT)

    # Create a second event stream with a different session ID but same cache size
    uncached_stream = EventStream('perf_test_uncached', file_store)
    uncached_stream.cache_size = 10

    # Add the same number of events to the uncached stream
    for i in range(num_events):
        uncached_stream.add_event(NullObservation(f'test{i}'), EventSource.AGENT)

    # Measure time to retrieve all events from cached stream
    start_time = time.time()
    cached_events = collect_events(cached_stream)
    cached_time = time.time() - start_time

    # Measure time to retrieve all events from uncached stream
    start_time = time.time()
    uncached_events = collect_events(uncached_stream)
    uncached_time = time.time() - start_time

    # Verify both streams returned a reasonable number of events
    assert len(cached_events) > 40, 'Cached stream should return most of the events'
    assert len(uncached_events) > 40, 'Uncached stream should return most of the events'

    # Log the performance difference
    logger_message = (
        f'Cached time: {cached_time:.4f}s, Uncached time: {uncached_time:.4f}s'
    )
    print(logger_message)

    # We're primarily checking functionality here, not strict performance metrics
    # In real-world scenarios with many more events, the performance difference would be more significant.
Test that using cache pages improves performance when retrieving many events.
tests/unit/test_event_stream.py