הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   זיהוי סוג הקובץ - PHP (https://hosts.co.il/forums/showthread.php?t=33381)

Tomer 23-10-06 00:00

ציטוט:

נכתב במקור על ידי RS324
הבילבול נוצר בגלל הדמיון תסתכל :

strchr -- Alias of strstr()

אבל כשיש פעמיים R
strrchr -- Find the last occurrence of a character in a string

מוצא את המופע האחרון של תו מסויים..

בגלל זה התבלבלתי בניהם

אני יעשה מבחן קטן ואני יגיד לך מה יותר יעיל.... הדרך שלי או הדרך שלך

אם אני לא טועה strrchr מייצג string reverse char (מציג את הסטרינג אחורנית)..

RS324 23-10-06 00:15

אוקי אז ככה :

יצרתי 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 

ועבורך משוגע...הדף פשוט הפסיק להגיב ולא נתן תוצאה |Rolleyes|

המסקנה הדרך שאני פרסמתי הכי יעילה
אחר כך של ATOM
ושל משוגע לא יעילה בכלל.

ניסיתי את הכל על המחשב שלי
אבל אתה מוזמן לקחת את הקבצים שפרסמתי את הקוד מקור שלהם פה ולבדוק על שרת שלך.

למרות שהמחשב שלי דיי אמין CENTRINO 1600 ליבה כפולה
וגיגה זיכרון....

meshuga 23-10-06 06:43

ציטוט:

נכתב במקור על ידי RS324
אוקי אז ככה :

יצרתי 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 

ועבורך משוגע...הדף פשוט הפסיק להגיב ולא נתן תוצאה |Rolleyes|

המסקנה הדרך שאני פרסמתי הכי יעילה
אחר כך של ATOM
ושל משוגע לא יעילה בכלל.

ניסיתי את הכל על המחשב שלי
אבל אתה מוזמן לקחת את הקבצים שפרסמתי את הקוד מקור שלהם פה ולבדוק על שרת שלך.

למרות שהמחשב שלי דיי אמין CENTRINO 1600 ליבה כפולה
וגיגה זיכרון....

אחלה ;)...נשתמש במה שאתה הצעת..מהיום...תודה.


כל הזמנים הם GMT +2. הזמן כעת הוא 01:11.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ