Comparison of CGI Performance in Some Programming Languages

Gene Michael Stover

$Date: 2008/04/20 17:25:56 $

Bourne shell version

#! /bin/sh

#
# $Header: /home/gene/library/website/docsrc/cgi-speed-0/RCS/body.html,v 395.1 2008/04/20 17:25:56 gene Exp $
#

echo content-type: text/html
echo ""

start=`date +%s`
echo \<html\>
echo \<head\>
echo \</head\>
echo \<body\>
echo \<h1\>words, Bourne shell version\</h1\>
section=0
while test $section -lt 10; do
    echo \<h2\>section $section\</h2\>
    paragraph=0
    while test $paragraph -lt 10; do
        echo \<p\>
        echo \<strong\>paragraph $paragraph\</strong\>
        word=0
        while test $word -lt 100; do
            echo $word
            word=`expr $word + 1`
        done
	echo \</p\>
        paragraph=`expr $paragraph + 1`
    done
    section=`expr $section + 1`
done
end=`date +%s`
seconds=`expr $end - $start`
echo \<p\>$seconds seconds\</p\>
echo \</body\>
echo \</html\>

Perl version

#! @PERL@ -T

use strict;
use warnings;
use CGI;

my $cgi = new CGI;
print $cgi->header ("text/html"), "\n\n";

my $start = time ();
print $cgi->start_html (), "\n";
print $cgi->head (), "\n";
print $cgi->start_body (), "\n";
print $cgi->h1 ("words, Perl version"), "\n";
foreach my $section (0 .. 9) {
    print $cgi->h2("section $section"), "\n";
    foreach my $paragraph (0 .. 9) {
	print $cgi->start_p (), "\n";
        print $cgi->strong ("paragraph $paragraph"), "\n";
        foreach my $word (0 .. 99) {
            print $word, "\n";
            ++$word;
        }
	print $cgi->end_p (), "\n";
    }
}
my $end = time ();
my $duration = $start - $end;
print $cgi->p ($duration, " seconds"), "\n";
print $cgi->end_body (), "\n";
print $cgi->end_html (), "\n";

cybertiggyr.com