If you are looking for an alternative to the xscreensaver package check out the lightweight xautolock. It tracks the user activity and fires a program when a specified time period is elapsed without user activity. Though it can be used with multiple locker programs, my personal preference is the lean xtrlock. The reason I prefer xtrlock is even if it locks the screen you can optionally view the desktop and any activity going on, e.g. a lengthy build.
Install xautolock and xtrlock on Ubuntu:
$ sudo apt-get install xautolock xtrlock
Run xautolock (10 minute timeout) with xtrlock:
$ xautolock -time 10 -locker "xtrlock -b"
You can add it to a startup script. Run top and see for yourself how lightweight xautolock is.