Skip to Content
Web Performance Tuning
book

Web Performance Tuning

by Patrick Killelea
October 1998
Intermediate to advanced
374 pages
12h 6m
English
O'Reilly Media, Inc.
Content preview from Web Performance Tuning

CGI Language-Specific Optimization Tips

While any programming language that includes the concept of standard in and standard out can be used to write a CGI, some languages are intrinsically more suited to the task than others. In this section, I will review the most common CGI languages (sh, Perl, and C), point out their strengths and weaknesses for CGI use, and give some language-specific optimization tips. But first, here are a few performance tips general to all languages:

  • Keep loops small.

  • Use table lookups rather than calculation, where practical.

  • Use integer rather than floating point math.

  • Avoid dynamic memory allocation.

  • Profile your code and optimize the most-used parts.

Shell Scripts

Unix Bourne shell scripts have the advantages of portability across Unix systems, easy file manipulation, and filtering. However, shell scripts are very slow to execute because they are interpreted and because they rely on other Unix programs for advanced functionality, with the result that sh scripts tend to fork a lot of new processes. This consumes time and resources. For example, if you wanted your sh CGI to search in all the files in the current directory for the word “foo” and output a sorted list of the results, eliminating duplicate lines, the programming is remarkably easy. Here is an entire CGI program that does exactly that:

#!/bin/sh
echo "Content-type: text/plain"
echo
grep -h foo * | sort | uniq

Although the time it took to write this program is negligible, we pay a large price at ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Web Performance Tuning, 2nd Edition

Web Performance Tuning, 2nd Edition

Patrick Killelea
Web performance basics

Web performance basics

Maximiliano Firtman

Publisher Resources

ISBN: 1565923790Catalog PageErrata