Making WordPress.org

Changeset 5496


Ignore:
Timestamp:
05/17/2017 07:23:19 PM (9 years ago)
Author:
iandunn
Message:

Events: Track query execution time to aid optimization

The test suite isn't representative of real-world usage, because by nature it's weighted heavily towards edge cases. Establishing a performance baseline is still useful when optimizing, though.

See #2823

Props dd32

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php

    r5491 r5496  
    1111 */
    1212function run_tests() {
     13        global $wpdb;
    1314        define( 'RUNNING_TESTS', true );
     15        define( 'SAVEQUERIES',   true );
     16
    1417        require_once( dirname( __DIR__ ) . '/index.php' );
    1518
    16         $failed = 0;
    17         $failed += test_get_location();
    18         $failed += test_get_city_from_coordinates();
    19 
    20         printf( "\n\nFinished running all tests. %d failed.\n", $failed );
     19        $tests_failed = 0;
     20        $tests_failed += test_get_location();
     21        $tests_failed += test_get_city_from_coordinates();
     22        $query_count  = count( $wpdb->queries );
     23        $query_time   = array_sum( array_column( $wpdb->queries, 1 ) );
     24
     25        printf(
     26                "\n\nFinished running all tests.\n\n* %d tests failed\n* %d queries ran in %f seconds\n* Average time per query: %f seconds\n",
     27                $tests_failed,
     28                $query_count,
     29                $query_time,
     30                $query_time / $query_count
     31        );
    2132}
    2233
Note: See TracChangeset for help on using the changeset viewer.