Fastest way to display 5000 post titles?

In my opinion and from what i’ve seen on testing. Using any WordPress function will slow things down dramatically. The fastest way i found to do this is by querying MySQL directly and grabbing only the things needed.

For example:

$products = $wpdb->get_results( "SELECT post_title, post_name FROM `wp_posts` WHERE post_type="products"", ARRAY_A );

    echo '<ol>';        

        foreach ($products as $product) {               

        echo '<li><a href="https://domain.com/products/'.$product['post_name']."https://wordpress.stackexchange.com/">'.$product['post_title'].'</a></li>';

        }        

    echo '</ol>';

It does it in a few ms (200~) with 1600 posts vs several seconds (3~) using WordPress.