Gustaf Neumann wrote:

What i did was to extend "configure" to look, if there is gettimeofday()
available
on the system. If it is, it bypasses the call to Tcl_GetTime() to get
the timestamp
via system call. On busy systems, Ns_GetTime() is one of the most
frequent calls, used e.g. for mutex timings, so this makes a difference.

The advantage of using Tcl_GetTime() is to delegate system dependencies
to Tcl.

This struck me as an interesting optimization question, so I wrote a quick program to test it (attached).

The only test environment at the moment I have is a linux VPS, so there's bound to be random influences from virtualization and whatever else happens to be running on the host at the time, so the noise is high. Still, I was not able to see any clear difference between gettimeofday(), Ns_GetTime, and Tcl_GetTime - on any given run any of the three was equally likely to be fastest.

time-int the program reports typically 2:1 system time:user time.

What this suggests to me is that - at least in my environment - the probable few hundred cycles difference in the implementations is completely lost to syscall and timeslice overhead or possibly cache line flushes, and it's not worth spending too much time worrying about it.

I'd be interested to hear anyone else's results and interpretations, or suggestions about how to better measure the differences in these.

-J
/*
 * test timing 
 * timing of raw gettimeofday vs Ns_GetTime and Tcl_GetTime
 * compile with: 
 * cc -O2 -I include -I /usr/include/tcl8.5 -o tt tt.c -ltcl8.5 -L lib -lnsd -lnsthread -lpthread
 */
 
#include "ns.h"
#include "tcl.h"
#include <stdio.h>
#include <sys/time.h>

void showdiff(char *fn, int count, struct timeval s, struct timeval e) {
    int diff=(e.tv_sec-s.tv_sec)*1000000 + (e.tv_usec-s.tv_usec);
    fprintf(stderr,"%s:\t%d usec %4.2f per\n",fn,diff,(double)diff/count);
}

int main(int argc, char** argv) {
    struct timeval s,e;
    struct timeval d;
    int diff,c;
    int diff_s,diff_us;
    int count=10000000;
    Tcl_Time timePtr;
    Ns_Time ntimePtr;

    if (argc == 2) {
        count=strtol(argv[1],NULL,10);
    }
    fprintf(stderr,"count: %d\n",count);

    /* warmup */
    for (c=0;c<100;c++) {
        gettimeofday(&d,NULL);
        Tcl_GetTime(&timePtr);
        Ns_GetTime(&ntimePtr);
    }

    gettimeofday(&s,NULL);
    for(c=0;c<count;c++) {
        Tcl_GetTime(&timePtr);
    }
    gettimeofday(&e,NULL);
    showdiff("Tcl_GetTime",count,s,e);

    gettimeofday(&s,NULL);
    for(c=0;c<count;c++) {
        Ns_GetTime(&ntimePtr);
    }
    gettimeofday(&e,NULL);
    showdiff("Ns_GetTime",count,s,e);

    gettimeofday(&s,NULL);
    for(c=0;c<count;c++) {
        gettimeofday(&d,NULL);
    }
    gettimeofday(&e,NULL);
    showdiff("gettimeofday",count,s,e);

}

------------------------------------------------------------------------------
Slashdot TV.  Videos for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to