Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 27-09-2004, 09:56 AM
bazet's Avatar
Novice Webmaster
 
Join Date: Aug 2001
Location: Ampang KL
Posts: 93
Rep Power: 90
bazet is on a distinguished road
Send a message via ICQ to bazet Send a message via AIM to bazet Send a message via Yahoo to bazet
Which is faster ?

Comparison #1
PHP Code:
$data ' Lorem ipsum ';
$data. =  ' danga bay ';
$data. = 'the lost empire of Troy ';
echo 
$data
or
PHP Code:
$data[] = ' Lorem ipsum ';
$data[] =  ' danga bay ';
$data[] = 'the lost empire of Troy ';
echo 
implode(""$data); 
Comparison #2
PHP Code:
echo "Lorem Ipsum"
or

PHP Code:
echo 'Lorem Ipsum'
Start learning write PHP for speed. These 2 examples show us how to achive speed in PHP.

Anyone have any URL for related topic ? ( Writing PHp for speed )..I just read it from ez Framework Documentation
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 28-09-2004, 04:59 PM
MHR's Avatar
MHR MHR is offline
Senior Webmaster
 
Join Date: Sep 2001
Location: epox
Posts: 435
Rep Power: 96
MHR is on a distinguished road
Send a message via ICQ to MHR Send a message via Yahoo to MHR
comparison 1, #1 faster, comp 2, #2 faster


check sitepoint forums, ade sticky topic pasal php tips and stuff
__________________
Munzir + "/^[Hh](a)(z)\1\2[iI]$/"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 28-09-2004, 06:17 PM
mysticmind's Avatar
Super Moderator
 
Join Date: Jun 2001
Location: Mystic Kingdoms
Posts: 2,687
Rep Power: 145
mysticmind will become famous soon enough mysticmind will become famous soon enough
Send a message via Yahoo to mysticmind
1. 1 sebab dia direct.. takder baca pusing sana sini pecah sana sini trace sana sini.. dari var terus ke result

2.?
aku kompius apa sebenarnya beza antara " dengan ' .
__________________
Personal's Blog! - Malaysian Artist!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 29-09-2004, 02:07 AM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
the ' should be faster than " because it does not need to care about the variable in the string
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 29-09-2004, 11:46 AM
MHR's Avatar
MHR MHR is offline
Senior Webmaster
 
Join Date: Sep 2001
Location: epox
Posts: 435
Rep Power: 96
MHR is on a distinguished road
Send a message via ICQ to MHR Send a message via Yahoo to MHR
yes. pandai lcf
__________________
Munzir + "/^[Hh](a)(z)\1\2[iI]$/"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 29-09-2004, 02:35 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
LOL *kembang kembang*
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 29-09-2004, 06:08 PM
Gemp-X's Avatar
Novice Webmaster
 
Join Date: Apr 2002
Location: kuantan, pahang
Posts: 58
Rep Power: 82
Gemp-X is on a distinguished road
Send a message via Yahoo to Gemp-X
tambahan utk no 2: kalau nak guna variable dalam string kene guna ( " )

contoh

PHP Code:
$burung="Ayam";
echo 
" \t1: Selsema $burung\n ";
echo 
' \t2: Selsema $burung\n '
output :
1: Selsema Ayam
\t2: Selsema $burung\n
__________________
http://sidik.org/

Last edited by Gemp-X; 30-09-2004 at 01:59 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 29-09-2004, 06:44 PM
MHR's Avatar
MHR MHR is offline
Senior Webmaster
 
Join Date: Sep 2001
Location: epox
Posts: 435
Rep Power: 96
MHR is on a distinguished road
Send a message via ICQ to MHR Send a message via Yahoo to MHR
guna variable dalam string is a bad practise. elok escape dan guna single quote
__________________
Munzir + "/^[Hh](a)(z)\1\2[iI]$/"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 30-09-2004, 02:21 AM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
a better way should be something like this:
PHP Code:
echo ' 2: Selsema' .  $burung
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 30-09-2004, 01:56 PM
Gemp-X's Avatar
Novice Webmaster
 
Join Date: Apr 2002
Location: kuantan, pahang
Posts: 58
Rep Power: 82
Gemp-X is on a distinguished road
Send a message via Yahoo to Gemp-X
but if we want to use escape character like '\n' (newline) or '\t'(tab)we should use ( " ) .
if we use ( ' ) , we should manually use return(Enter) or tab key, to make newline or tab in the output

eg : both output will be

selsema
burung
PHP Code:
echo "selsema\n burung";

echo 
'selsema
burung'

__________________
http://sidik.org/

Last edited by Gemp-X; 30-09-2004 at 02:01 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 30-09-2004, 06:19 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
is it for webpages? I thought you will use <br /> for a new line?
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 30-09-2004, 08:49 PM
Gemp-X's Avatar
Novice Webmaster
 
Join Date: Apr 2002
Location: kuantan, pahang
Posts: 58
Rep Power: 82
Gemp-X is on a distinguished road
Send a message via Yahoo to Gemp-X
i mean output = html code (the source), not the output by browser, just to make our html tidy, with proper newline and tabbed

for instance
PHP Code:
echo "\nLorem ipsum dolor sit amet, <br /> \n consectetuer adipiscing elit.<br />\n Donec molestie"
html source produced will be:
Code:
Lorem ipsum dolor sit amet, <br />
consectetuer adipiscing elit. <br />
Donec molestie

of course the output by browser will be:

Lorem ipsum dolor sit amet,
consectetuer adipiscing elit.
Donec molestie
__________________
http://sidik.org/

Last edited by Gemp-X; 30-09-2004 at 08:54 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 01-10-2004, 10:15 AM
bazet's Avatar
Novice Webmaster
 
Join Date: Aug 2001
Location: Ampang KL
Posts: 93
Rep Power: 90
bazet is on a distinguished road
Send a message via ICQ to bazet Send a message via AIM to bazet Send a message via Yahoo to bazet
Comparison #1
=================
Aku rasa #2 faster than #1.Sebabya,
$data = " test";
$data .= "test2"; // ini akan consume more memory
so

Nih result dia :

http://cms.arl.net.my/fallujah/comparison.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 01-10-2004, 10:23 AM
bazet's Avatar
Novice Webmaster
 
Join Date: Aug 2001
Location: Ampang KL
Posts: 93
Rep Power: 90
bazet is on a distinguished road
Send a message via ICQ to bazet Send a message via AIM to bazet Send a message via Yahoo to bazet
err..I was wrong

#1 is fater in comparison 1
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 01-10-2004, 11:05 AM
Gemp-X's Avatar
Novice Webmaster
 
Join Date: Apr 2002
Location: kuantan, pahang
Posts: 58
Rep Power: 82
Gemp-X is on a distinguished road
Send a message via Yahoo to Gemp-X
i think this comparison has some bias
cuba ubah kedudukan atas tukar bawah, result dia akan berbeza.
to ensure the result is not biased, run each in 2 different files

try modified code ni untuk comparison 1
PHP Code:
<?
/* mari kita lihat sapa yg laju */
function getmicrotime()
{
  list(
$usec$sec) = explode(" ",microtime());
  return ((float)
$usec + (float)$sec);
}

if (
$_GET['type']==1||!isset($_GET['type'])){
echo 
'(using $data )<br>';

$script_start2 getmicrotime();
$data ' Lorem ipsum '
$data .=  ' danga bay ';
$data .= 'the lost empire of Troy ';
echo 
$data;
$script_end2=getmicrotime();
echo 
'<br>Time taken:' sprintf("%.9f",($script_end2 $script_start2)) . 'secs';

echo 
'<br><a href="'.$PHP_SELF.'?type=2" >satu lagi</a>';
unset(
$data);
unset(
$burung);
}elseif(
$_GET['type']==2){
echo 
'(using  $data[])<br>';

$script_start1 getmicrotime();
$data[] = ' Lorem ipsum ';
$data[] =  ' danga bay ';
$data[] = 'the lost empire of Troy ';
echo 
implode(""$data);
$script_end1=getmicrotime();
echo 
'<br>Time taken:' sprintf("%.9f",($script_end1 $script_start1)) . 'secs';

echo 
'<br><a href="'.$PHP_SELF.'?type=1" >satu lagi</a>';
unset(
$data);
unset(
$burung);
}

?>
no 1
(using $data )
Lorem ipsum danga bay the lost empire of Troy
Time taken:0.000053167secs

no 2
(using $data[])
Lorem ipsum danga bay the lost empire of Troy
Time taken:0.000056982secs

#using $data[] implode a bit slower

(berapa banyak kali daa aku ubah,hehe. yang ni betul ni)
__________________
http://sidik.org/

Last edited by Gemp-X; 01-10-2004 at 12:04 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply