Test program execution time in various environments in thinkphp projects
do not use caching:
The code is as follows |
Copy Code |
<?php Header ("Content-type:text/html;charset=utf-8");
$starttime =caltime ()//Start time $articles =array (); Loop out 500 article information For ($i =0 $i <100; $i + +) { $sql = "Select a.*,c.* from Blog_article as a,blog_category as C where a.reid=c.id limit 0,5"; $articles =array_merge ($articles, M (' article ')->query ($sql)); } $overtime =caltime ();//End time Echo ' does not use cached conditions the program execution time is: '. ($overtime-$starttime). ' Seconds '; ?> |
Result: The program execution time is 0.0600001811981 seconds without the use of a cache condition:
File Caching:
code is as follows |
copy code |
<?php Header (" Content-type:text/html;charset=utf-8 "); $starttime =caltime ();//Start time $articles =s (' articles '); if (! $articles) { $articles =array () //Loop out 500 www.111cn.net article Information for ($i =0 $i <100; $i + +) { $sql = ' Select a.*,c.* from Blog_article as a, Blog_category as C where a.reid=c.id limit 0,5 "; $articles =array_merge ($articles, M (' article ')->query ($sql)); } S (' articles ', $articles, 60); } $overtime =caltime ();//End time Echo uses file caching conditions for program execution time: '. ( $overtime-$starttime). ' Seconds '; ? |
Results: The program execution time using file caching is 0.00999999046326 seconds
The code is as follows |
Copy Code |
<?php Header ("Content-type:text/html;charset=utf-8"); $starttime =caltime ()//Start time $mem =new Memcache (); if (! $mem- >connect (' 127.0.0.1 ', 11211)} { echo ' connection failed '; } $articles = $mem->get (' articles '); if (! $articles) { $articles =array (); //Loop out 500 article Information for ($i =0; $i <100; $i + +) { $sql = ' Select a.*,c.* from Blog_article as a,blog_category as C Where a.reid=c.id limit 0,5 "; $articles =array_merge ($articles, M (' article ')->query ($sql)); } $mem->set (' articles ', $articles, memcache_compressed,60); } $overtime =caltime ();//End time Echo ' uses memcache cache conditions for program execution time: '. ( $overtime-$starttime). ' Seconds '; ? |
Results: The program execution time is 0.00999999046326 seconds using the memcache cache condition
The code is as follows |
Copy Code |
<?php Header ("Content-type:text/html;charset=utf-8"); $starttime =caltime ()//Start time $redis =new Redis (); $redis- >connect (' 127.0.0.1 ', ' 6379 '); if (! $redis) { echo ' connection failed '; } $articles = $redis->get (' articles '); if (! $articles) { $articles =array () //Loop out 500 www.111cn.net article Information for ($i =0 $i <100; $i + +) { $sql = ' Select a.*,c.* from Blog_article as a, Blog_category as C where a.reid=c.id limit 0,5 "; $articles =array_merge ($articles, M (' article ')->query ($sql)); } $redis->setex (' articles ', $articles); } $overtime =caltime ();//End time Echo ' uses Redis cache conditions for program execution time: '. ( $overtime-$starttime). ' Seconds '; ? |
Results: The program execution time is 0.00999999046326 seconds using the Redis cache condition
Visible with caching, the program executes 6 times times faster than it does when the cache is not used,
But different caches, because the data is not very large, almost no difference