Using high precision clock should avoid corner case...

where time(NULL) returns e.g. 5, but time is 5.99.
Thanks to @kacfengine for spotting this.