[thelist] PHP echoing...

Liam Delahunty ldelahunty at britstream.com
Mon Aug 19 09:24:01 CDT 2002


jon steele wrote:
Double quotes with embedded variables were faster by up to 5 times as I
recall. Then single quotes
with the concatenation operator (.), and then jumping in and out of php
using <??>.


On my windows ME box, and my Linux server I just did this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>test the speed of different printing instructions</title>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
</head>
<body>

<?php

print ("<form action=\"$PHP_SELF\" method=\"POST\">\n");
print ("Outer Loop: <input type=\"Text\" name=\"loop_a\"
value=\"$loop_a\"><br>\n");
print ("Inner Loop: <input type=\"Text\" name=\"loop_b\"
value=\"$loop_b\"><br>\n");
print ("bar: <input type=\"Text\" name=\"bar\" value=\"$bar\"><br>\n");

if ($result)
	{
	$check = "checked";
	}
	else
	{
	$check = ""	;
	}

print ("Show each result: <input type=\"Checkbox\" $check
name=\"result\"><br>\n");
print ("<input type=\"Submit\" name=\"submit\" value=\"submit\"><br>\n");
print ("</form>\n");

function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
    }


if ($submit)
	{
	if (!is_numeric($loop_a) || !is_numeric($loop_a))
		{
		print ("<p>Hold it cowboy, numbers only in the loop.</p>");
		exit;
		}

	if (($loop_a > 1000) || ($loop_b > 1000) || ($loop_a * $loop_b > 100000))
		{
		print ("<p>What's whith the big numbers chaps? Please make them smaller
than 1000, and the sum less than 100,000</p>");
		exit;
		}


	if ($bar == "")
		{
		$bar = "Hello mum. ";
		}
		else
		{
		$bar = htmlentities($bar);
		}

	print ("<p>Outer loop: $loop_a, Inner loop: $loop_b bar: $bar</p>");

	for ($i=0; $i<$loop_a; $i++)
		{
		$time_start = getmicrotime();
		for ($x=0; $x<$loop_b; $x++)
			{
			print '<!-- foo ' .$bar. ' baz -->';
			}
		$time_end = getmicrotime();
		$time_a = $time_end - $time_start;

		$time_start = getmicrotime();
		for ($x=0; $x<$loop_b; $x++)
			{
			print "<!-- foo $bar baz -->";
			}
		$time_end = getmicrotime();
		$time_b = $time_end - $time_start;

		if ($time_a < $time_b)
			{
			$diff_time = $time_b - $time_a;
			$dots++;
			if ($result != "") { print("<p> Dots win #$i: $diff_time</p>\n"); }
			}
			else
			{
			$diff_time = $time_a - $time_b;
			$quotes++;
			if ($result != "") {print ("<p>Quotes win #$i: $diff_time</p>\n"); }
			}
		}
	print ("<p>Dots $dots v Quotes $quotes </p>");

	}


?>
</body>
</html>

The dots easily have it with a big outer loop and not many inner loops
(8/10), but with bigger inner loops it evens out...

I may well experiment more if I get time...


best,
Liam




More information about the thelist mailing list