in reply to My CGI is slow, but I don't think it's my fault.

It doesn't necessarily need to be the host (a sleep 18 in your code would give similar timing), but it does sound like a system issue.

Have you checked how busy that machine is? Check some of these commands:

uptime free ulimit df -H ps aux
You get the idea.

If those aren't the issue, is connecting to the database a problem? Opening sockets? What else does your code do that interacts with the OS?