אוקי אז ככה :
יצרתי 3 קבצים שונים :
שכל קובץ מכיל את הנתונים לפי מה שפרסמנו.
הקובץ שלי :
PHP קוד:
<?php
$filename = "this.is.my.file.name.and.i.like.it.txt";
function rs324_way($filename)
{
return array_pop(explode('.',$filename));
}
$rs324_start = microtime();
for ($i = 0; $i <= 100000;$i++)
{
rs324_way($filename);
}
$rs324_end = microtime();
echo "for 100,000 times rs324_way took ".($rs324_end - $rs324_start)." seconds";
?>
הקובץ של ATOM-BOMB :
PHP קוד:
<?php
$filename = "this.is.my.file.name.and.i.like.it.txt";
function atom_way($filename)
{
$type = explode(".",$filename); // חלוקת הקובץ לפי מספר הנקודות
$count = count($type);
return $type[$count - 1];
}
$atom_start = microtime();
for ($i = 0; $i <= 100000;$i++)
{
atom_way($filename);
}
$atom_end = microtime();
echo "for 100,000 times atom_way took ".($atom_end - $atom_start)." seconds";
?>
והקובץ של משוגע :
PHP קוד:
<?php
$filename = "this.is.my.file.name.and.i.like.it.txt";
function meshuga_way($filename)
{
return substr(strrchr($name, "."), 1);
}
$meshuga_start = microtime();
for ($i = 0; $i <= 100000;$i++)
{
meshuga_way($filename);
}
$meshuga_end = microtime();
echo "for 100,000 times meshuga_way took ".($meshuga_end - $meshuga_start)." seconds";
?>
עכשיו, המבחן הוא בדיקה של כמה זמן לוקח עבור 100 אלף פעמים שאותה פונקציה צריכה לרוץ.
והנה התוצאות :
שלי :
PHP קוד:
for 100,000 times rs324_way took 0.152966 seconds
של ATOM :
PHP קוד:
for 100,000 times atom_way took 0.756723 seconds
ועבורך משוגע...הדף פשוט הפסיק להגיב ולא נתן תוצאה
המסקנה הדרך שאני פרסמתי הכי יעילה
אחר כך של ATOM
ושל משוגע לא יעילה בכלל.
ניסיתי את הכל על המחשב שלי
אבל אתה מוזמן לקחת את הקבצים שפרסמתי את הקוד מקור שלהם פה ולבדוק על שרת שלך.
למרות שהמחשב שלי דיי אמין CENTRINO 1600 ליבה כפולה
וגיגה זיכרון....