</detail01>
XML;
$xml
= simplexml_load_string(
$string
);
foreach
(
$data
as
$d
) {
$xml
->addChild('Row'," ID=\" {$d['id']} \" Name=\" {$d['name']}\" " );
}
return
$xml
->asXML(); ;
}
调用时每个都加上大数循环操作,并记录时间
代码如下:
$loop
=10000;
$xml
='';
switch
(
$_GET
['id']){
case
1:
$ts
=
$this
->microtime_float();
for
(
$i
=0;
$i
<
$loop
;
$i
++)
$xml
=
$this
->directWriteXml(
$depdata
);
$te
=
$this
->microtime_float();
$t
=
$te
-
$ts
;
$this
->assign('times',
$t
);
$this
->assign('method','直接写');
break
;
case
2:
$ts
=
$this
->microtime_float();
for
(
$i
=0;
$i
<
$loop
;
$i
++)
$xml
=
$this
->useDomDocument(
$depdata
);
$te
=
$this
->microtime_float();
$t
=
$te
-
$ts
;
$this
->assign('times',
$t
);
$this
->assign('method','DomDocument');
break
;
case
3:
$ts
=
$this
->microtime_float();
for
(
$i
=0;
$i
<
$loop
;
$i
++)
$xml
=
$this
->useSimpleXML(
$depdata
);
$te
=
$this
->microtime_float();
$t
=
$te
-
$ts
;
$this
->assign('times',
$t
);
$this
->assign('method','SimpleXML');
break
;
}