"""Time a local model on your own computer. Usage (Ollama must be installed and running; the model must be downloaded): python3 time-a-model.py qwen2.5:7b SHORT-PROMPT.txt python3 time-a-model.py qwen2.5:7b LONG-PROMPT-HEADER.txt LONG-INPUT.txt It sends the prompt to Ollama on this computer only (http://127.0.0.1:11434), prints the answer, then prints how long the model took to read your text, how long it took to write, and its writing speed in words per second. Most adults read about 4 words per second. Note: Ollama reuses a prompt it has just seen, so a second identical run looks faster than a real fresh read. Change the prompt or restart Ollama between runs if you want a fresh reading time. """ import json import sys import time import urllib.request from pathlib import Path if len(sys.argv) < 3: sys.exit(__doc__) model = sys.argv[1] prompt = "".join(Path(p).read_text() for p in sys.argv[2:]) body = json.dumps({ "model": model, "system": "Follow the user request. Use only supplied facts. No tools or external sources.", "prompt": prompt, "stream": False, "options": {"temperature": 0.2, "seed": 42, "num_ctx": 8192}, }).encode() started = time.monotonic() request = urllib.request.Request("http://127.0.0.1:11434/api/generate", data=body, headers={"Content-Type": "application/json"}) with urllib.request.urlopen(request, timeout=900) as response: result = json.loads(response.read()) total = time.monotonic() - started answer = result.get("response", "") writing = result["eval_duration"] / 1e9 print(answer) print("\n---") print(f"Model: {model}") print(f"Loading the model: {result.get('load_duration', 0) / 1e9:.1f} s") print(f"Reading your text: {result.get('prompt_eval_duration', 0) / 1e9:.1f} s ({result.get('prompt_eval_count')} tokens)") print(f"Writing the answer: {writing:.1f} s") print(f"Writing speed: {len(answer.split()) / writing:.1f} words per second") print(f"Total time: {total:.1f} s")