Oldukça birkaç kişi zaten cevap olarak, sadece eğlence için, burada (do I dare calling it that ? ) çok hızlı bir kriter bulunuyor; Aşağıdaki kodu göz önünde bulundurun:
$num = 1;
$list = array_fill(0, 5000, str_repeat('1234567890', $num));
$before = microtime(true);
for ($i=0 ; $i<10000 ; $i++) {
$str = serialize($list);
}
$after = microtime(true);
var_dump($after-$before);
var_dump(memory_get_peak_usage());
I'm running this on PHP 5.2.6 (the one bundled with Ubuntu jaunty).
And, yes, there are only values ; no keys ; and the values are quite simple : no object, no sub-array, no nothing but string.
$num = 1
, olsun için:
float(11.8147978783)
int(1702688)
$num = 10
, olsun için:
float(13.1230671406)
int(2612104)
Ve, için $num = 100
, olsun:
float(63.2925770283)
int(11621760)
Yani, dizinin her bir elemanı uzun sürer (seems fair, actually), bir büyük görünüyor. Ancak, 100 kat daha büyük elemanlar için, çok daha uzun 100 kez yapmayız ...
Now, with an array of 50000 elements, instead of 5000, which means this part of the code is changed :
$list = array_fill(0, 50000, str_repeat('1234567890', $num));
$num = 1
ile, olsun:
float(158.236332178)
int(15750752)
O 1 için aldı süresini göz önüne alındığında, ben $ = 10 num ne $ num = 100 ya bu koşma olmayacak ...
Yes, of course, in a real situation, you wouldn't be doing this 10000 times ; so let's try with only 10 iterations of the for loop.
Için $num = 1
,
float(0.206310987473)
int(15750752)
Için $num = 10
,
float(0.272629022598)
int(24849832)
Ve için $num = 100
,
float(0.895547151566)
int(114949792)
Yeah, that's almost 1 second -- and quite a bit of memory used ^^
*(No, this is not a production server : I have a pretty high memory_limit on this development machine ^^ )*
So, in the end, to be a bit shorter than those number -- and, yes, you can have numbers say whatever you want them to -- I wouldn't say there is a "limit" as in "hardcoded" in PHP, but you'll end up facing one of those :
max_execution_time
(genellikle, bir web sunucusu üzerinde, bu 30 saniyeden daha fazla asla)
memory_limit
(bir web sunucusu üzerine, bu genellikle 32MB fazla muco değil)
- Sen sunucusu yük olacak: bu büyük serialize-döngü 1 çalışırken, benim CPU 1 aldı; Eğer aynı anda aynı sayfada kullanıcıların oldukça bir çift olan varsa, ben bunu verecek ne hayal edelim ;-)
- Lütfen kullanıcı sabır ^ ^
But, except if you are really serializing long arrays of big data, I am not sure it will matter that much...
And you must take into consideration the amount of time/CPU-load using that cache might help you gain ;-)
Yine de bilmek en iyi yolu gerçek veriler ile, kendiniz test olacağını ;-)
And you might also want to take a look at what Xdebug can do when it comes to profiling : this kind of situation is one of those it is useful for!