KBD

Keith Devens .com

Sunday, March 21, 2010 Flag waving
If we wish to count lines of code, we should not regard them as *lines produced* but as *lines spent*. – Edsger Dijkstra
← 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

Joe (http://www.medlawplus.com) wrote:

Well said Steven! The price for webdna has to tumble if they want to increase the installed base. I love the language but we're a very small community.

∴ Joe | 19-Feb-2009 12:06pm est | http://www.medlawplus.com | #11074

Donovan (http://www.webdna.us) wrote:

Just ran across this blog and wanted to address some of Steven concerns quickly (since Joe revived this old thread) ;-)... in full disclousure, WebDNA has changed hands recently (bought by many long-time developers) and I am one of many of those "hands".

Steven's "reasons":
"Reason #1: The cost of the software itself:"
With our new release (6.2) prices are now reduced by up to a fifth of their previous prices... and yes, I agreed with Steven's 2004 posting.. so I hope our price changes address this concern. Yes PHP is still free.. but we all know that the real cost in developing apps is in the time it takes to create features. WebDNA wins hands-down there.

"Reason #2: The availability of hosting services"
This is not a significant issue in my opinion.. yes, PHP has many more installs out there, but one query to us, or a query to the talk list, and you can find ample hosts for your needs.. including GoDaddy and many of the bigger server farms.

"Reason #3: Great support by lots of experienced users"
I think WebDNA's talk list and forum members are top-notch.. many long-time developers there. Practically no question leaves without a solution. ;-)

"Reason #4: Lots of free code snippets available"
I can't argue with this one. Though we have a lot of good community offerings for WebDNA, we are well behind what is available out there in PHP. However, this is something we are working hard on to bridge the gap. Perhaps a good point for us in this subject right now is the fact that it doesn't take long to create/replicate most of those free code snippets from scratch using WebDNA. ;-)

"Reason #5: The availability of cheap programmers"
I'm sure this is correct.. however, having been in the business for 10+ years myself I think the saying:"you get what you pay for" is an important consideration... and also, I would argue that production is cheaper in many cases because of WebDNA's syntax and it's power in creating cost effective solutions. So when talking in terms of monetary cost for a project, there are a lot of arguments for using WebDNA.

"Reason #6: Webdna could 'disappear' at any time"
I was overwhelmed when the WebDNA community banned together to acquire the rights. At this point, Though I may have been concerned about this in 2005-2007, I can honestly say that there is nothing to worry about. it's hear to stay, and is only going to get better.

Donovan

∴ Donovan | 18-Sep-2009 1:03pm est | http://www.webdna.us | #11372

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)
:

March 2010
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



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

Recent comments XML

new⇒Spider solitaire

I to am somewhat addicted to​spending too much time on SS.  I​have been stu...

stupid_horse: Mar 20, 10:34pm

I hate ASP.NET

I hate ASP... I was doing wonders​with PHP, then suddenly one of my​clients...

Johnies: Mar 17, 6:14am

Quantum physics and free will

I knew you were going to say that....

Tom Massey: Mar 15, 9:26pm

Generated in about 0.113s.

(Used 8 db queries)