Without knowing anything about the application, it's very
hard to say what to do. If of the 10 seconds it takes, it
spends 9.5 in the database, don't bother speeding up the
code - speed up your database. If it spends a lot of time
doing I/O, get faster disks, a better controller, or more
memory. If you are sure it's the code, find the bottleneck(s),
and rewrite that, perhaps in C.