Page 1 of 2 1 2 LastLast
Results 1 to 15 of 24

Thread: Which is faster ?

  1. #1
    Join Date
    Aug 2001
    Location
    Ampang KL
    Posts
    93
    Rep Power
    222

    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

  2. #2
    Join Date
    Sep 2001
    Location
    epox
    Posts
    432
    Rep Power
    227
    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]$/"

  3. #3
    Join Date
    Jun 2001
    Location
    Mystic Kingdoms
    Posts
    2,749
    Rep Power
    277
    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 ' .

  4. #4
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249
    the ' should be faster than " because it does not need to care about the variable in the string

  5. #5
    Join Date
    Sep 2001
    Location
    epox
    Posts
    432
    Rep Power
    227
    yes. pandai lcf
    Munzir + "/^[Hh](a)(z)\1\2[iI]$/"

  6. #6
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249
    LOL *kembang kembang*

  7. #7
    Join Date
    Apr 2002
    Location
    kuantan, pahang
    Posts
    58
    Rep Power
    213
    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
    Last edited by Gemp-X; 30-09-2004 at 01:59 PM.

  8. #8
    Join Date
    Sep 2001
    Location
    epox
    Posts
    432
    Rep Power
    227
    guna variable dalam string is a bad practise. elok escape dan guna single quote
    Munzir + "/^[Hh](a)(z)\1\2[iI]$/"

  9. #9
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249
    a better way should be something like this:
    PHP Code:
    echo ' 2: Selsema' .  $burung

  10. #10
    Join Date
    Apr 2002
    Location
    kuantan, pahang
    Posts
    58
    Rep Power
    213
    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'

    Last edited by Gemp-X; 30-09-2004 at 02:01 PM.

  11. #11
    Join Date
    Feb 2003
    Location
    Kluang, Johor
    Posts
    2,367
    Rep Power
    249
    is it for webpages? I thought you will use <br /> for a new line?

  12. #12
    Join Date
    Apr 2002
    Location
    kuantan, pahang
    Posts
    58
    Rep Power
    213
    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
    Last edited by Gemp-X; 30-09-2004 at 08:54 PM.

  13. #13
    Join Date
    Aug 2001
    Location
    Ampang KL
    Posts
    93
    Rep Power
    222
    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

  14. #14
    Join Date
    Aug 2001
    Location
    Ampang KL
    Posts
    93
    Rep Power
    222
    err..I was wrong

    #1 is fater in comparison 1

  15. #15
    Join Date
    Apr 2002
    Location
    kuantan, pahang
    Posts
    58
    Rep Power
    213
    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)
    Last edited by Gemp-X; 01-10-2004 at 12:04 PM.

Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Looking for Faster Server
    By amanz in forum Paid Hosting Discussion Forum
    Replies: 7
    Last Post: 18-12-2014, 07:00 PM
  2. VPN services for a faster and secure download
    By CheetahVPN in forum Showcase
    Replies: 0
    Last Post: 21-10-2009, 01:39 PM
  3. The Faster Online Service to build online your Business
    By kingrapid in forum Other Webmaster-related Services and Promotion
    Replies: 0
    Last Post: 26-06-2009, 05:18 AM
  4. Make Google index your site faster
    By jawa in forum Other Internet Marketing Methods
    Replies: 15
    Last Post: 11-12-2004, 03:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112