This script tests the response times of different OpenAI models by sending the same question to each model and measuring how long it takes to get a response.
- Python 3.x (if not installed, on macOS use:
brew install python3) - pip (comes with Python3)
-
Clone this repository
-
Create and activate a virtual environment:
# Create virtual environment python3 -m venv venv # Activate virtual environment # On macOS/Linux: source venv/bin/activate # On Windows: # venv\Scripts\activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Copy the
.env.examplefile to.env:cp .env.example .env
-
Edit the
.envfile and add your OpenAI API key:OPENAI_API_KEY=your_api_key_here
Make sure your virtual environment is activated (you should see (venv) at the start of your prompt), then run the script:
python3 test_response_times.pyThe script will:
- Test each model with the same question
- Measure response times
- Print results to the console
- Save detailed results to
response_times.json
To modify the test:
- Edit the
MODELSlist in the script to test different models - Change the
TEST_QUESTIONvariable to test with a different prompt - Adjust other parameters like temperature in the
get_model_responsefunction
The script generates two types of output:
- Console output with a summary of results
- A JSON file (
response_times.json) with detailed results including:- Model name
- Success/failure status
- Response time
- Response content (if successful)
- Error message (if failed)
- Timestamp
When you're done, you can deactivate the virtual environment:
deactivateIf you see "command not found" errors:
- Make sure Python3 is installed:
which python3 - If Python3 is not found, on macOS install it with:
brew install python3 - Always use
python3instead ofpythonto ensure you're using Python 3