def file_replace(file_name: Path, old_text: str, new_text: str) -> Iterator[None]:
    """
    Replace some text in `file_name`, and change it back.
    """
    file_text = ""
    if old_text:
        file_text = file_name.read_text(encoding="utf-8")
        if old_text not in file_text:
            raise Exception("Old text {old_text!r} not found in {file_name}")
        updated_text = file_text.replace(old_text, new_text)
        file_name.write_text(updated_text, encoding="utf-8")
    try:
        yield
    finally:
        if old_text:
            file_name.write_text(file_text, encoding="utf-8")

    Replace some text in `file_name`, and change it back.
    
benchmark/benchmark.py