This script measures the loading time of a webpage using Playwright. It simulates multiple users accessing a specified URL concurrently and calculates the average loading time over multiple iterations.
- Node.js (latest LTS recommended)
- Playwright package installed
- Python 3.8+ (for data analysis and dashboard)
- Install dependencies:
npm install playwright
- Install Python dependencies:
pip install -r requirements.txt
- Run the script:
ts-node measureLoadingTime.spec.ts
- The script will:
- Launch multiple browser instances concurrently.
- Measure the time taken to load
https://google.com. - Repeat the process for different user counts.
- Output the average loading time for each test case.
- Start Jupyter Notebook:
jupyter notebook
- Open
loading_times_analysis.ipynbto explore the data and get insights:- Loading times by hour of day
- Loading times by day of week
- Loading times by month
- Average loading times by number of users
- Time series analysis
- Statistical summaries
- Run the dashboard using Voila:
voila dashboard.ipynb
- The dashboard will open in your browser and provides:
- Interactive filtering by number of users
- Multiple visualization views (Time Series, By Hour, By Day of Week, By Month, Distribution)
- Real-time statistics
- Professional, user-friendly interface
Alternatively, you can also view the dashboard in Jupyter:
jupyter notebook dashboard.ipynb- Modify the
usersparameter to change the number of concurrent browser instances. - Adjust the
iterationsparameter to control the number of test repetitions. - Change the
page.gotoURL to test a different webpage.
Average loading time for 1 user(s) over 5 iterations: 120 ms
Average loading time for 2 user(s) over 5 iterations: 140 ms
...
This project provides multiple ways to visualize and analyze the collected data:
- R Shiny Dashboard (
app.R): Interactive web application for real-time data visualization - Jupyter Notebook Analysis (
loading_times_analysis.ipynb): Comprehensive exploratory data analysis - Voila Dashboard (
dashboard.ipynb): Interactive Python-based dashboard for data exploration
- Ensure network conditions are stable for accurate results.
- Running many concurrent users may consume significant system resources.
- The script defaults to testing
https://google.com, but this can be modified as needed. - Results can be analyzed to track performance trends over time.
- This project uses
https://google.comsolely as a stable test case for personal learning and educational purposes. - It makes a low and limited number of automated requests, and does not involve scraping, user interaction automation, or high-frequency traffic.
- This project is provided as-is for educational use. If you choose to modify or adapt it, you are solely responsible for ensuring that your usage complies with all applicable laws and remains respectful of any target site's terms of service, rate limits, and infrastructure.