View Source is faster then browser

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

I know that the title isn't descriptive enough to tell you what I really mean. What I meant to say is when you click "View Source", it generates the results faster than the browser itself. SO if 'View Source' showed the page rather then the source, it would generally be faster then the browser. At least that is how I see it with the following test I made...
PHP Code: [ Select ]
<?php
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);
 
// All you need is 256 spaces first
echo str_repeat(" ", 256)."<pre>"; ob_flush();
$n = 0;
$p = 0;
for($i=0;$i<60;$i++)
{
   for($i=1;$i<57;$i++)
   {
      echo "$i ";
      ob_flush();
      usleep(1);
      ++$n;
   }
   ++$p;
   echo "<strong> ~ $n , $p</strong>\n";
}
?>
  1. <?php
  2. @apache_setenv('no-gzip', 1);
  3. @ini_set('zlib.output_compression', 0);
  4. @ini_set('implicit_flush', 1);
  5. for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
  6. ob_implicit_flush(1);
  7.  
  8. // All you need is 256 spaces first
  9. echo str_repeat(" ", 256)."<pre>"; ob_flush();
  10. $n = 0;
  11. $p = 0;
  12. for($i=0;$i<60;$i++)
  13. {
  14.    for($i=1;$i<57;$i++)
  15.    {
  16.       echo "$i ";
  17.       ob_flush();
  18.       usleep(1);
  19.       ++$n;
  20.    }
  21.    ++$p;
  22.    echo "<strong> ~ $n , $p</strong>\n";
  23. }
  24. ?>

For me it averaged about 18-19 columns in the browser and 28-31 columns in the 'View Source'.

I tested this in Firefox, and to test it be generated in 'View Source' refresh the page, hit 'Stop' and then view the source... Shouldn't be any harder then that. To test this in the browser, simple hit refresh and that's it...
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

I don't really understand what you're getting at here? :scratchhead:
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

:scratchhead: :hmm: What I understand is that bogey wants to say the above code displays faster in view source rather than browser? Well explanation may be like this (trying, not sure)

Every browser searches for style information, document type and other meta tags, since you omit that browser fails to find and applies defaults. I think this is the overhead time. While in source code, browser is just reading the generated source and displaying it. That's why it's faster

but even if you give doc type and other style info, it will still be slow, cause this time, browser has to fetch those style info and place them accordingly on the browser :D

So if you are good enough to interpret the view source then browse all sites using view source, cause either way it's fast :lol:
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

lol I just checked this and it seemed fast... I don't really know how the browser works or anything... I'm not that kind of a nerd... okay, I went to far and I was joking... I just didn't dwell into browsers so much... just how they show my sites is good enough :roll:

Yes, dark_lord's explanation sounds about right...
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

View source displays faster because the code has already been parsed by the browser and is most likely cached somewhere. Besides, all view source is doing is displaying the text used to display the page. It doesn't have to interpret it.

When a browser gets a URI it automatically begins parsing the code. In the case of a website I believe they use "top to bottom" parsing. In most cases browsers begin displaying the web page as soon as it has enough information to do so. That's why you see pages display in segments as the tokens are passed from the parser to the interpreter.

Wiki is a little incomplete but here's a rough definition.
http://en.wikipedia.org/wiki/Parsing
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

No no no... when you hit stop on my script and then view the source, it basically generates the source... it doesn't take it from the stopped script.

So I hit stop, view the source, check the number of columns there are, then close the source, hit refresh, and then see how many columns there are in the browser... I know that the source basically takes it from the cache or something like that...
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

ok i have adapted the above code to display time intervals to print one row and cumulative sum of ten rows
Code: [ Select ]
 
  <?php
 
 
   @apache_setenv('no-gzip', 1);
   @ini_set('zlib.output_compression', 0);
   @ini_set('implicit_flush', 1);
   for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
   ob_implicit_flush(1);
   
   // All you need is 256 spaces first
   echo str_repeat(" ", 256)."<pre>"; ob_flush();
   $n = 0;
   $p = 0;
   $time = 0;
   $k = 0;
   for($i=0;$i<60;$i++)
   {
       $k++;
       $starttime = microtime();
       $startarray = explode(" ", $starttime);
       $starttime = $startarray[1] + $startarray[0];
       $stime = time();
       for($i=1;$i<57;$i++)
       {
           echo "$i ";
           ob_flush();
           usleep(1);
           ++$n;
       }
       ++$p;
       echo "<strong> ~ $n , $p</strong>\n";
       $endtime = microtime();
       $endarray = explode(" ", $endtime);
       $endtime = $endarray[1] + $endarray[0];
       $totaltime = $endtime - $starttime;
       $totaltime = round($totaltime,5);
       echo "Page Loads in $totaltime seconds.\n";
       $time += $totaltime;
       if($k=="10")
       {
            echo "Cumulative of ten: <strong>".$time."</strong>\n"; //this prints the time taken to display 10 rows
            $k = 0;
            $time = 0;
       }
 
   }
   
 
   ?>
 
  1.  
  2.   <?php
  3.  
  4.  
  5.    @apache_setenv('no-gzip', 1);
  6.    @ini_set('zlib.output_compression', 0);
  7.    @ini_set('implicit_flush', 1);
  8.    for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
  9.    ob_implicit_flush(1);
  10.    
  11.    // All you need is 256 spaces first
  12.    echo str_repeat(" ", 256)."<pre>"; ob_flush();
  13.    $n = 0;
  14.    $p = 0;
  15.    $time = 0;
  16.    $k = 0;
  17.    for($i=0;$i<60;$i++)
  18.    {
  19.        $k++;
  20.        $starttime = microtime();
  21.        $startarray = explode(" ", $starttime);
  22.        $starttime = $startarray[1] + $startarray[0];
  23.        $stime = time();
  24.        for($i=1;$i<57;$i++)
  25.        {
  26.            echo "$i ";
  27.            ob_flush();
  28.            usleep(1);
  29.            ++$n;
  30.        }
  31.        ++$p;
  32.        echo "<strong> ~ $n , $p</strong>\n";
  33.        $endtime = microtime();
  34.        $endarray = explode(" ", $endtime);
  35.        $endtime = $endarray[1] + $endarray[0];
  36.        $totaltime = $endtime - $starttime;
  37.        $totaltime = round($totaltime,5);
  38.        echo "Page Loads in $totaltime seconds.\n";
  39.        $time += $totaltime;
  40.        if($k=="10")
  41.        {
  42.             echo "Cumulative of ten: <strong>".$time."</strong>\n"; //this prints the time taken to display 10 rows
  43.             $k = 0;
  44.             $time = 0;
  45.        }
  46.  
  47.    }
  48.    
  49.  
  50.    ?>
  51.  


you will see the first one is always less in 'view source' than in browser cause at that time browsers looks for style information (which is the overhead time) :wink:
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

It actually went faster on both... on browser the average was 21 columns and in the view source the average was 33... Your code had more code to it yet it was faster... :lol:

I'm not as good of a programmer :( oh well... I pointed this out because I found it to be interesting and not knowing how browsers actually work.
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

come on bogey none is good! So don't get sad :D

and on the above code check the milliseconds printed with every rows

the first one in view source has to be less from the browser. :)

try it out

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 86 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.