# Performance

Every wrapper has some overhead. We do our best to make this number as small as possible. One unique *Layout* or *Post Selection* on a page would only effect this by 0.01 second&#x73;**\*** overhead compared to the usual way with coding. It’s impossible to notice these tiny numbers visually without testing it.

**\***&#x54;his number was given by our tests, codes of the tests are provided below. Numbers can be different depending on your hosting opportunities.&#x20;

## Test of a Layout

{% code overflow="wrap" %}

```php
/**
 * Goal: check overhead of using the Advanced Views (shortcode) way comparing with the clear code way without any caching
 *
 * Test: Render of 4 post (1 post field + 4 ACF fields) for each way (clear code/shortcode)
 * (every way has its own posts and own ACF Group per each post, so there is totally no internal cache in the test)
 *
 * Result: overhead for one Layout is 9 MS (14 MS per post for the shortcode way VS 5 MS per post for the clear code way, 280%)
 * (55 MS for the shortcode way VS 20 MS for the clear code way. (55 MS - 20 MS) / 4 Layouts = 9 MS per Layout)
 */
add_shortcode('layout-test', function () {
    $shortcodePostIds = [1093, 2012, 2014, 2016,];
    $viewIds          = [895, 2087, 2088, 2089];
    $codePostIds      = [2170, 2172, 2174, 2176,];
    $shortcodeMarkup  = '';
    $codeMarkup       = '';

    $shortcodeStartTime = microtime(true);
    for ($i = 0; $i < 4; $i++) {
        $shortcodeMarkup .= do_shortcode(
            sprintf(
                '[acf-layout id="%s" object-id="%s"]',
                $viewIds[$i],
                $shortcodePostIds[$i]
            )
        );
    }
    $timeForShortcode     = microtime(true) - $shortcodeStartTime;
    $timeForShortcodeInMs = round($timeForShortcode * 1000);

    $codeStartTime = microtime(true);
    foreach ($codePostIds as $codePostId) {
        $postTitle = get_the_title($codePostId);
        // Text
        $description = get_field('description2', $codePostId);
        // Date Picker d/m/Y
        $year = get_field('year2', $codePostId);
        // Wysiwyg Editor
        $longDescription = get_field('long_description2', $codePostId);
        // Number
        $price = get_field('price2', $codePostId);

        $codeMarkup .= '<div class="acf-view acf-view--id--895 acf-view--object-id--{object-id}">';

        $codeMarkup .= '<div class="acf-view__row _post_title">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $postTitle);
        $codeMarkup .= '</div>';

        $codeMarkup .= '<div class="acf-view__row description">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $description);
        $codeMarkup .= '</div>';

        $codeMarkup .= '<div class="acf-view__row year">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $year);
        $codeMarkup .= '</div>';

        $codeMarkup .= '<div class="acf-view__row long_description">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $longDescription);
        $codeMarkup .= '</div>';

        $codeMarkup .= '<div class="acf-view__row price">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $price);
        $codeMarkup .= '</div>';


        $codeMarkup .= '</div>';
    }
    $timeForCode     = microtime(true) - $codeStartTime;
    $timeForCodeInMs = round($timeForCode * 1000);

    $overheadForOneViewInMs          = round((($timeForShortcode / 4) - ($timeForCode / 4)) * 1000);
    $overheadForOneViewInPercentages = round((($timeForShortcode / 4) / ($timeForCode / 4)) * 100);

    return $codeMarkup . sprintf('<h3>Time for 4 posts with code in ms: %s</h3>', $timeForCodeInMs)
           . $shortcodeMarkup . sprintf('<h3>Time for 4 posts with shortcode in ms: %s</h3>', $timeForShortcodeInMs)
           . sprintf('<h3>Overhead for one Layout in ms: %s</h3>', $overheadForOneViewInMs)
           . sprintf('<h3>Overhead for one Layout in percentages: %s</h3>', $overheadForOneViewInPercentages);
});
```

{% endcode %}

## Test of a Post Selection

{% code overflow="wrap" %}

```php
/**
 * Goal: check overhead of using the Advanced Views Post Selection (shortcode) way comparing with the clear code way
 *
 * Test: Query and render 4 post (1 post field + 4 ACF fields) for each way (clear code/shortcode)
 * (every way has its own posts and own ACF Group per each post, so there is no internal WP/ACF cache in the test)
 *
 * Result: overhead for one Post Selection is 10 MS (147%)
 * (31 MS for the shortcode way VS 21 MS for the clear code way. 31 MS - 21 MS = 10 MS)
 *
 * Note : Though Post Selection uses a Layout to render, common overhead is much lower than the Layout's overhead * amount of posts in the results,
 * because our plugin has internal cache and the Layout's data & markup is cached.
 * It means work by markup creation is done only once regardless of count of posts in Post Selection results.
 */
add_shortcode('post-selection-test', function () {
    $shortcodeMarkup = '';
    $codeMarkup      = '';

    $shortcodeStartTime   = microtime(true);
    $shortcodeMarkup      .= do_shortcode(' [acf-post-selection id="1129"]');
    $timeForShortcode     = microtime(true) - $shortcodeStartTime;
    $timeForShortcodeInMs = round($timeForShortcode * 1000);

    $codeStartTime = microtime(true);
    $queryArgs     = [
        'post_type'      => 'page',
        'post_status'    => 'publish',
        'posts_per_page' => 4,
        'order'          => 'ASC',
        'orderby'        => 'none',
        'post__in'       => [
            2170,
            2172,
            2174,
            2176
        ]
    ];
    $query         = new \WP_Query($queryArgs);
    $codePostIds   = $query->get_posts();
    foreach ($codePostIds as $codePostId) {
        $postTitle = get_the_title($codePostId);
        // Text
        $description = get_field('description2', $codePostId);
        // Date Picker d/m/Y
        $year = get_field('year2', $codePostId);
        // Wysiwyg Editor
        $longDescription = get_field('long_description2', $codePostId);
        // Number
        $price = get_field('price2', $codePostId);

        $codeMarkup .= '<div class="acf-view acf-view--id--895 acf-view--object-id--{object-id}">';

        $codeMarkup .= '<div class="acf-view__row _post_title">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $postTitle);
        $codeMarkup .= '</div>';

        $codeMarkup .= '<div class="acf-view__row description">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $description);
        $codeMarkup .= '</div>';

        $codeMarkup .= '<div class="acf-view__row year">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $year);
        $codeMarkup .= '</div>';

        $codeMarkup .= '<div class="acf-view__row long_description">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $longDescription);
        $codeMarkup .= '</div>';

        $codeMarkup .= '<div class="acf-view__row price">';
        $codeMarkup .= sprintf('<div class="acf-view__field">%s</div>', $price);
        $codeMarkup .= '</div>';


        $codeMarkup .= '</div>';
    }
    $timeForCode     = microtime(true) - $codeStartTime;
    $timeForCodeInMs = round($timeForCode * 1000);

    $overheadForOneCardInMs          = round(($timeForShortcode - $timeForCode) * 1000);
    $overheadForOneCardInPercentages = round(($timeForShortcode / $timeForCode) * 100);

    return $codeMarkup . sprintf('<h3>Time for query & display 4 posts with code in ms: %s</h3>', $timeForCodeInMs)
           . $shortcodeMarkup . sprintf(
               '<h3>Time for query & display 4 posts with shortcode in ms: %s</h3>',
               $timeForShortcodeInMs
           )
           . sprintf('<h3>Overhead for one Post Selection in ms: %s</h3>', $overheadForOneCardInMs)
           . sprintf('<h3>Overhead for one Post Selection in percentages: %s</h3>', $overheadForOneCardInPercentages);
});
```

{% endcode %}


---

# 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://wplake.gitbook.io/advanced-views/customization/performance.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.
