Test 100,000 and 1 million cache reads and writes using the local environment and the results are as follows.
Environment
Win7 x64 AMD7750双核 内存82.4.95.5.122.2.7
Code
functionconvert($size){$unit=Array(' B ',' KB ',' MB ',' GB ',' TB ',' PB ');return@round ($size/POW (1024x768, ($i= Floor (log ($size,1024x768)))),2) .' '.$unit[$i];} functioncachefile($key){$dir=' Cache ';if(!is_dir ($dir) &&!mkdir ($dir)) {ThrowNewException("can ' t make dir $dir"); }$filepath=$dir. Directory_separator. sprintf'%x ', CRC32 ($key));if(! (File_exists ($filepath) && ($data= File_get_contents ($filepath)) &&!Empty($data))) {$data= Date (' y-m-d h:i:s '); File_put_contents ($filepath,$data); }return$data;} functioncachemem($key){$mem=NewMemcache ();$mem->connect (' 127.0.0.1 ',11211);$data=$mem->get ($key);if(Empty($data)) {$data= Date (' y-m-d h:i:s ');$mem->set ($key,$data); }return$data;}$t 1= Microtime (true);$i=0;$limit= +* -;//100,000 times$data=NULL; while($i<$limit) {//$data = Cachefile ($i);$data= Cachemem ($i);$i++;}$timeUse= Microtime (true) -$t 1;$arr= [' cost '= sprintf ('%.7fs ',$timeUse),' mem '= = Convert (Memory_get_usage ())];var_dump ($arr);
Results 10,000 times
花费时间 内存耗费File 1.9sec250kbMemcache 11sec250kb
Results 100,000 times
花费时间 内存耗费File94s 251.18KBMemcache 超时120
Memcache 100,000 tests failed, error content is as follows
inonline37Warning: Memcache::gettoin D:\localhost\speed.phpWarning: Memcache::settoinonline41timeof120secondsinonline38
Conclusion
memcacheUsed to do the cache is not the direct file cache, the reason for this test is because I did not use the memcache to do the cache, directly using the file cache (single server), the results are directly identified as the technical Officer 很菜鸟 . But I passed this test, although it is under win, but why Memcahe performance is not as good as file?
Or is there a mistake in the way I test? Solving default.fu@foxmail.com
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the Memcache cache rather than the direct file cache? , including the aspects of the content, want to be interested in PHP tutorial friends helpful.