# Performance Testing

If you don’t want users leaving the app you have to think of performance. In fact nowadays if you site is not fast enough you get even “honored” with [the badge of shame](https://www.theverge.com/2019/11/11/20959865/google-chrome-slow-sites-badge-system-chrome-dev-summit-2019) from Google. Thus [performance budget](https://addyosmani.com/blog/performance-budgets/) is one of the aspects we address with end-to-end tests and include in CI/CD pipeline to ensure new releases do comply our requirements.&#x20;

With Puppetry we can assert that:&#x20;

* Page loading times comply given restrictions&#x20;
* Total weight of assets (JavaScript, CSS, images, media, fonts, XHR) requested on the page satisfies given budget.&#x20;
* Total number of requested of assets satisfies given budget&#x20;

## Milestone timings&#x20;

With `page.assertPerformanceTiming` method we can establish budget for loading times. Namely:

* **Page loading**: the whole process of navigation and page load
* **Redirection**: the time taken by document request redirections
* **Network latency**: the time taken to fetch app cache, lookup domain, establish TCP connection, send request, receive response
* **Page processing**: the time taken for page load once the page is received from the server

![Asserting page loading times](/files/-Lu2OjX-wJy7cnHleqi4)

In case of assertion failure we get a report like this:

![Page loading budget report](/files/-Lu2OeylKoxBFHyAl4IF)

## Quantity-based metrics

With `page.assertPerformanceAssetWeight` method we can assert the total weight of assets (JavaScript, CSS, images, media, fonts, XHR) requested on the page

![Asserting total weight of requested assets ](/files/-Lu2L1z9apr2OOpIW1X4)

In case of assertion failure we get a report like this:

![Assertion failed](/files/-Lu2PJcfJB3lCovdo2OM)

By clicking on **Download performance report**

![Download performance report button](/files/-Lu2PNYSjZQ1T-YtkTc0)

we can get the network activity details

![Performance report as a text file](/files/-Lu2PQvFQ7BXnWLSyPDq)

With `page.assertPerformanceAssetCount` method we can assert the total number of assets (JavaScript, CSS, images, media, fonts, XHR) requested on the page

![Asserting total number of requested assets ](/files/-Lu2L5UAR59D_NC6yeuf)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.puppetry.app/testing-techniques/performance-testing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
