Testing apply_filters() times

Testing how long it takes to assign a variable versus assigning through WordPress’ apply_filters(). Filters are core to WordPress, but I haven’t yet looked at the total number of apply_filters() calls used throughout the code. The answer to this question is that calling a non-existing filter before assignment is about 21 times more costly than simply assigning it. That’s nothing compared to the cost of actually doing some filtering, however.

<?php
require 'wp-load.php'; 

$start_time = $end_time = $i = $assigned_a = $assigned_b = $assigned_c = 0;

$start_time = microtime( TRUE );
for( $i = 0; $i <= 100000; $i++)
{
    $assigned_a = 'This is a string & stuff!';
}
$end_time = microtime( TRUE );
echo 'Test A: '. ( $end_time - $start_time ) ." seconds \n\n";
//Test A: 0.011314868927002 seconds 


$start_time = microtime( TRUE );
for( $i = 0; $i <= 100000; $i++)
{
    $assigned_b = apply_filters( 'this_is_not_a_real_filter' , 'This is a string & stuff!' );
}
$end_time = microtime( TRUE );
echo 'Test B: '. ( $end_time - $start_time ) ." seconds \n\n";
//Test B: 0.23782300949097 seconds 


$start_time = microtime( TRUE );
for( $i = 0; $i <= 100000; $i++)
{
    $assigned_c = apply_filters( 'sanitize_title_with_dashes' , 'This is a string & stuff!' );
}
$end_time = microtime( TRUE );
echo 'Test B: '. ( $end_time - $start_time ) ." seconds \n\n";
//Test C: 12.843906879425 seconds