thanks. very interesting.
im sure i would have tried to do somthing with xml and spent a week scraching my head.
here is a larger version of that test..
i am just switching over to php, and found these results interesting.
<?
function ss_timing_start ($name = ‘default’) {
global $ss_timing_start_times;
$ss_timing_start_times[$name] = explode(' ', microtime());
}
function ss_timing_stop ($name = ‘default’) {
global $ss_timing_stop_times;
$ss_timing_stop_times[$name] = explode(' ', microtime());
}
function ss_timing_current ($name = ‘default’) {
global $ss_timing_start_times, $ss_timing_stop_times;
if (!isset($ss_timing_start_times[$name])) {
return 0;
}
if (!isset($ss_timing_stop_times[$name])) {
$stop_time = explode(' ', microtime());
}
else {
$stop_time = $ss_timing_stop_times[$name];
}
$current = $stop_time[1] - $ss_timing_start_times[$name][1];
$current += $stop_time[0] - $ss_timing_start_times[$name][0];
return $current;
}
?>
<head>
<title>hmm?</title>
</head>
<body>
<h2>echo vs. string vs. inline</h2>
<b>echo test</b>
<br>
<? ss_timing_start('echo'); ?>
<?
for ($i=0; $i<1000; $i++) {
echo $i." ";
}
?>
<? ss_timing_stop('echo'); ?>
<br>
<b>string test</b>
<br>
<? ss_timing_start(str); ?>
<?
$str = '';
for ($i=0; $i<1000; $i++) {
$str .= $i." ";
}
echo $str;
?>
<? ss_timing_stop(str); ?>
<br>
<b>inline test</b>
<br>
<? ss_timing_start(inline); ?>
<?
for ($i=0; $i<1000; $i++) {
?>
666
<?
}
?>
<? ss_timing_stop(inline); ?>
<br>
<br>
<h2>Results</h2>
echo - <? echo ss_timing_current('echo') ?>
<br>
str - <? echo ss_timing_current(str) ?>
<br>
inline - <? echo ss_timing_current(inline) ?>
<hr>
<h2>echo quote vs. apos</h2>
<b>quoted test</b>
<? ss_timing_start(quoted); ?>
<?
for ($i=0; $i<1000; $i++) {
echo("natas ");
}
?>
<? ss_timing_stop(quoted); ?>
<br>
<b>aposted test</b>
<? ss_timing_start(apos); ?>
<?
for ($i=0; $i<1000; $i++) {
echo 'natas ';
}
?>
<? ss_timing_stop(apos); ?>
<br>
<h2>Results</h2>
quoted - <? echo ss_timing_current(quoted) ?>
<br>
apos - <? echo ss_timing_current(apos) ?>
<h2>shorthand vs. long</h2>
<b>shorthand test</b>
<? ss_timing_start(shorthand); ?>
<?
for ($i=0; $i<1000; $i++) {
?>
666<?='natas' ?>
<?
}
?>
<? ss_timing_stop(shorthand); ?>
<br>
<b>longhand test</b>
<? ss_timing_start(longhand); ?>
<?
for ($i=0; $i<1000; $i++) {
?>
666<? echo("natas"); ?>
<?
}
?>
<? ss_timing_stop(longhand); ?>
<br>
<h2>Results</h2>
shorthand - <? echo ss_timing_current(shorthand) ?>
<br>
longhand - <? echo ss_timing_current(longhand) ?>
<br>
<hr>
<br>
<h2>Test str_replace vs ereg</h2>
<? $string = 'Testing with <i>emphasis</i>'; ?>
<br>
<?='<b>string to replace:</b> '.$string; ?>
<br>
<br>
<b>str_replace</b>
<br>
<? ss_timing_start('str_replace'); ?>
<?
for ($i=0; $i<1000; $i++) {
$string=(str_replace('i>', 'b>', $string).'<br>');
}
?>
<? ss_timing_stop('str_replace'); ?>
<?='str_replace(\'i>\', \'b>\', $string)'?>
<br>
<b>ereg_replace</b>
<br>
<? ss_timing_start(ereg); ?>
<?
for ($i=0; $i<1000; $i++) {
$string=(ereg_replace('i>', 'b>', $string).'<br>');
}
?>
<? ss_timing_stop(ereg); ?>
<?='ereg_replace(\'i>\', \'b>\', $string)'?>
<br>
<b>ereg_pattern</b>
<br>
<? ss_timing_start(ereg_pattern); ?>
<?php
for ($i=0; $i<1000; $i++) {
ereg_replace('<([/])i>', '<\1b>', $string).'<br>';
}
?>
<? ss_timing_stop(ereg_pattern); ?>
<?='ereg_replace(\'<([/])i>\', \'<\1b>\', $string'?>
<br>
<h2>Results</h2>
str_replace - <?php echo ss_timing_current(str_replace) ?>
<br>
ereg - <?php echo ss_timing_current(ereg) ?>
<br>
ereg_pattern - <?php echo ss_timing_current(ereg_pattern) ?>
<br>
<hr>
<?
$string = 'Testing with <em>emphasis</em> on a long string so we can see how the <em>different</em> replace functions perform.';
ss_timing_start('str_replace');
for ($i=0; $i<10000; $i++) {
str_replace('em>', 'strong>', $string).'<br>';
}
ss_timing_stop('str_replace');
ss_timing_start(ereg);
for ($i=0; $i<10000; $i++) {
ereg_replace('em>', 'strong>', $string).'<br>';
}
ss_timing_stop(ereg);
ss_timing_start(eregi);
for ($i=0; $i<10000; $i++) {
eregi_replace('em>', 'strong>', $string).'<br>';
}
ss_timing_stop(eregi);
ss_timing_start(ereg_pattern);
for ($i=0; $i<10000; $i++) {
ereg_replace('<([/]*)em>', '<\1strong>', $string).'<br>';
}
ss_timing_stop(ereg_pattern);
ss_timing_start(eregi_pattern);
for ($i=0; $i<10000; $i++) {
eregi_replace('<([/]*)em>', '<\1strong>', $string).'<br>';
}
ss_timing_stop(eregi_pattern);
echo "10,000 iterations gave:";
echo "<p>str_replace - ".ss_timing_current(str_replace);
echo "<p>ereg - ".ss_timing_current(ereg);
echo "<p>ereg_pattern - ".ss_timing_current(ereg_pattern);
echo "<p>eregi - ".ss_timing_current(eregi);
?>
</body>