diff options
author | ajs <ajs> | 2007-04-29 15:48:22 +0000 |
---|---|---|
committer | ajs <ajs> | 2007-04-29 15:48:22 +0000 |
commit | 4b143474930638edbbb9e5bd462cdc19436f345e (patch) | |
tree | d66a5c3363140297d5730f13df470af166877104 /lib | |
parent | 885b4d1d8a98ad30c8f276222ff27a314e63723b (diff) | |
download | quagga-4b143474930638edbbb9e5bd462cdc19436f345e.tar.bz2 quagga-4b143474930638edbbb9e5bd462cdc19436f345e.tar.xz |
[logging] Minor performance tweak
2007-04-29 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* log.c: (quagga_timestamp) Optimize the subsecond timestamp generation.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ChangeLog | 4 | ||||
-rw-r--r-- | lib/log.c | 25 |
2 files changed, 20 insertions, 9 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog index 3e515f87..f8fdd11e 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2007-04-29 Andrew J. Schorr <ajschorr@alumni.princeton.edu> + + * log.c: (quagga_timestamp) Optimize the subsecond timestamp generation. + 2007-04-28 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * command.c: (config_write_host) Save "log timestamp precision" @@ -100,18 +100,25 @@ quagga_timestamp(int timestamp_precision, char *buf, size_t buflen) (buflen > cache.len+1+timestamp_precision)) { /* should we worry about locale issues? */ - long divisor = 100000; - char *p = buf+cache.len; - *p++ = '.'; + static const int divisor[] = {0, 100000, 10000, 1000, 100, 10, 1}; + int prec; + char *p = buf+cache.len+1+(prec = timestamp_precision); + *p-- = '\0'; + while (prec > 6) + /* this is unlikely to happen, but protect anyway */ + { + *p-- = '0'; + prec--; + } + clock.tv_usec /= divisor[prec]; do { - *p++ = '0'+(clock.tv_usec/divisor); - clock.tv_usec %= divisor; - divisor /= 10; + *p-- = '0'+(clock.tv_usec % 10); + clock.tv_usec /= 10; } - while (--timestamp_precision > 0); - *p = '\0'; - return p-buf; + while (--prec > 0); + *p = '.'; + return cache.len+1+timestamp_precision; } buf[cache.len] = '\0'; return cache.len; |