Is calling function_exists() faster or slower that apply_filters()

I don’t know if one is faster or slower than the other, but I would suggest that using apply_filters() is the better approach, because it is cleaner, and more intuitive (in the sense of doing things the “WordPress way”).

EDIT

If you’re doing comparison tests, shouldn’t you compare the time required to execute the following:

This:

<?php
if ( ! function_exists( 'taco_party' ) ) {
    function taco_party( $salsa = true ) {
        return $salsa;
    }
}

function taco_party( $salsa = true ) {
    return $salsa;
}
?>

Versus This:

<?php
function taco_party( $salsa = true ) {
    return apply_filters( 'taco-party', $salsa );
}
function hot_salsa() {
    $salsa = true;
    return $salsa;
}
add_filter( 'taco-party', 'hot_salsa' );
?>

It’s not just the time required to check for the existence of the function or filter, but rather the time required to do something.

Leave a Comment