<?php
// gc_enable();

/**
 * Test single quotes
 * @return float microtime
 */
function single_quotes() {
	$blog_id = 12345;
	$key = 'blog_charset';
	$i = 0;
	$tmp = array();
	// gc_collect_cycles();

	$start = microtime( true );
	while ( $i < 10000 ) {
		$tmp[] = $blog_id . '-' . $key . '-blog_option';
		++$i;
	}

	return ( microtime( true ) - $start );
}

/**
 * Test double quotes
 * @return float microtime
 */
function double_quotes() {
	$blog_id = 12345;
	$key = "blog_charset";
	$i = 0;
	$tmp = array();
	// gc_collect_cycles();

	$start = microtime( true );
	while ( $i < 10000 ) {
		$tmp[] = $blog_id . "-" . $key . "-blog_option";
		++$i;
	}

	return ( microtime( true ) - $start );
}

$single = array();
$double = array();
$i = 0;

while ( $i < 1000 ) {
	// try to randomize any GC bias
	if ( ($i % 2) === 1 ) {
		$double[] = double_quotes();
		$single[] = single_quotes();
	} else {
		$single[] = single_quotes();
		$double[] = double_quotes();
	}
	++$i;
}
unset( $i );

echo 'Total iterations: ' . count( $single ) . PHP_EOL . PHP_EOL;

$total_single = array_sum( $single );
echo "Total single: $total_single" . PHP_EOL;

$total_double = array_sum( $double );
echo "Total double: $total_double" . PHP_EOL;
if ( $total_single < $total_double )
	echo 'Single-quoted string solution completed ' . ( $total_double - $total_single ) . ' microseconds faster.' . PHP_EOL;
else
	echo 'Double-quoted string solution completed ' . ( $total_single - $total_double ) . ' microseconds faster.' . PHP_EOL;

echo PHP_EOL;

echo 'Average single: ' . ( $total_single / count( $single ) ) . PHP_EOL;
echo 'Average double: ' . ( $total_double / count( $double ) ) . PHP_EOL;

?>