当前位置:Gxlcms > PHP教程 > php数据性能小测

php数据性能小测

时间:2021-07-01 10:21:17 帮助过:3人阅读

今天看到一个同事写的php程序 突然想测试一下php的两种数组定义方式的性能差别


简单测试代码如下:

1.使用array关键字

 0,			'b' => 1,			'c' => 2,			'd' => 3,			'e' => 4,			'f' => 5,			'g' => 6,			'h' => 7,			'i' => 8,			'j' => 9,			'k' => 10,			'l' => 11,			'm' => 12,			'n' => 13,			'o' => 14,			'p' => 15,			'q' => 16,			'r' => 17,			's' => 18,			't' => 19,			'u' => 20,			'v' => 21,			'w' => 22,			'x' => 23,			'y' => 24,			'z' => 25,			'a1' => 0,			'b1' => 1,			'c1' => 2,			'd1' => 3,			'e1' => 4,			'f1' => 5,			'g1' => 6,			'h1' => 7,			'i1' => 8,			'j1' => 9,			'k1' => 10,			'l1' => 11,			'm1' => 12,			'n1' => 13,			'o1' => 14,			'p1' => 15,			'q1' => 16,			'r1' => 17,			's1' => 18,			't1' => 19,			'u1' => 20,			'v1' => 21,			'w1' => 22,			'x1' => 23,			'y1' => 24,			'z1' => 25	);}echo '
';echo time();exit();

执行时间:1398407484 - 1398407432 = 52s

2.不使用array关键字

';echo time();exit();

执行时间 1398407870 - 1398407832 = 38s


二者性能相关巨大

所以在定义数组时最好使用单行定义的方式尽管这可样可以让你多写一些代码 不过一些更高的性能还是不错的 尤其是在访问量大的网站上 尤其你又是C出身程序员

人气教程排行