KBD

Keith Devens .com

Thursday, November 20, 2008 Flag waving
... we can never use experience to prove the inductive principle without begging the question. Thus we must... forgo all justification... – Bertrand Russell ("On Induction" in The Problems of Philosophy)
← Draft postsAwesome skateboarding video →

Daily link icon Wednesday, December 3, 2003

Page execution time code on my site

Someone recently asked me in an e-mail how I generate the "This page took about x seconds to generate" message on my site. As I started to reply, and pasted the code I use into my e-mail client, I realized that this would work much better as a weblog entry (you get source-code highlighting here). So, here's how I do it:

I have one function, called timer().

<?php
function timer($finish false){
    static 
$start_frac_sec$start_sec$end_frac_sec$end_sec;
    if(
$finish){
        list(
$end_frac_sec,$end_sec) = explode(" "microtime());
        echo 
'<p style="font-size: smaller">This page took about ' .
            
round(
                (
                    (
$end_sec $start_sec)
                    + (
$end_frac_sec $start_frac_sec)
                ),
            
4) . ' seconds to generate.</p>\n';
    }else{
        list(
$start_frac_sec,$start_sec) = explode(" "microtime());
    }
}
?>

Because of the $finish parameter, you can use one function to both keep track of the time (which works without global variables because of the static variables) and print it when you're done. So, I call timer() around the start of my script, and timer(true) around the end of it.

← Draft postsAwesome skateboarding video →

Comments XML gif

J$ (http://alpha-geek.com) wrote:

What do you use to syntx highlight your code and generate the HTML output? vim?

∴ J$ | 3-Dec-2003 4:36pm est | http://alpha-geek.com | #3424

Keith (http://keithdevens.com/) wrote:

No, I use PHP's built-in highlight function. PHP's the only source code I can highlight right now. I had planned originally to make other simple highlighters (I think you can get very competent highlighting for a particular language with some simple regular expressions), and now that I'm switching my site to Python I'll have to come up with something different than just using PHP's built-in function.

Keith | 3-Dec-2003 4:40pm est | http://keithdevens.com/ | #3425

Keith (http://keithdevens.com/) wrote:

Oh, I just realized why my explanation above might not make total sense. Remember that all my weblog posts are entered in my own "StructuredText" variant, and are rendered on the fly by my weblog software during a request. Code is typed in plain within some "code" tags that indicate that something is code and what language the code is in, and then upon page rendering that code is passed to PHP's highlight function and I then print the resulting syntax-highlighted code (after changing <font> tags to <span style="..."> tags using string replaces)

Keith | 3-Dec-2003 4:49pm est | http://keithdevens.com/ | #3426

Amazing BrianB wrote:

wtf was all that wasted code? in webdna:
at bottom of page:
this page took [format .4f][math][elapsedtime]/60[/math][/format] seconds to generate.

What is it about PHP that makes people want to use it???

∴ Amazing BrianB | 5-Dec-2003 8:42pm est | #3457

Steven Atkins wrote:

> What is it about PHP that makes people want to use it???

Here's what I think:

Reason #1: The cost of the software itself ...
PHP is open source and free, whereas webdna costs thousands of dollars for the first purchase and hundreds (or thousands) more every time a new version comes out or every time you want to add another new domain to the server. Then there is the issue of dealing with new bugs in webdna which are released in every new version, thus making your upgrade purchase uneless for several months until the company finally fixes a few of the biggest bugs ...

Reason #2: The availability of hosting services ...
PHP is already installed and functioning properly on just about every hosting service in the world, including those cheap $5 a month hosting services. But if you're using webdna you will be lucky to find a decent (and also affordable) hosting service no matter how hard you look for one.

Reason #3: Great support by lots of experienced users ...
Since a lot of people use PHP there are lots of support groups, lists, etc. out there for both new and experienced PHP programmers. Webdna has a miniscule following by comparison, and SmithMicro employees seldom respond to inquiries on their own talk list unless you repeat yourself several times.

Reason #4: Lots of free code snippets available ...
There are lots of free downloadable PHP examples available that offer "cut and paste" solutions to many web programming tasks, thus saving lots of development time. Webdna has little that's useful in the way of downloadable "cut and paste" functions and solutions. Instead the webdna authors all seem to prefer to be paid for their work instead of sharing freely.

Reason #5: The availability of cheap programmers ...
Since PHP is free and so well known and supported, there are lots of PHP programmers available for hire at far lower rates than the rates webdna programmers charge. So even though a project may take longer to code in PHP, it can still cost the customer less overall. And customers like lower prices.

Reason #6: Webdna could 'disappear' at any time ...
PHP will never die because it is supported by a huge community of web developers that demand no money and expect nothing but good software. On the other hand, SmithMicro (the owners of webdna) could go out of business at any time, or they could simply decide to just stop selling webdna if they find it doesn't make enough money for them any more. Then where does that leave all the webdna programmers? Out in the cold, that's where ... probably wishing they had learned PHP instead.

Don't get me wrong, webdna is a wonderful program to use! It's fast and elegant and it can handle most web features and capabilities with ease. In this respect it is much more enjoyable to use than PHP -- from a programmer's standpoint.

But from a web site owner's position, all the OTHER factors are the "real world" issues that determine which program the owner will accept ... and in the real world, PHP wins on many of the practical points that web site owners consider to be very important.

∴ Steven Atkins | 17-Jan-2004 2:06am est | #3771

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

November 2008
SunMonTueWedThuFriSat
 1
2345678
9101112131415
16171819202122
23242526272829
30 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 4 posts

Recent comments XML

new⇒Java join function

Meh, don't have null strings in​your string arrays imo, but you're​welcome ...

Keith: Nov 19, 7:51pm

Girls, please don't get breast implants

sorry but another thing i have to​make a comment on about you​men...the men...

happynow: Nov 17, 11:36pm

Books by Vincent Cheung

to all Cheung​fans:

read:

http://www.progin​osko.com/aquascum/cheung.h...

Zamir: Nov 16, 9:07am

Spider solitaire

To undo or not to undo that is the​question.
I'm an undoer. 
My dad​was n...

Can Turk: Nov 15, 2:50pm

Generated in about 0.268s.

(Used 8 db queries)

mobile phone