Annotation of OpenXM/src/hgm/fisher-bingham/src/ko-time.c, Revision 1.1
1.1 ! takayama 1: #include <stdio.h>
! 2: #include <stdlib.h>
! 3: #include <time.h>
! 4: #include <string.h>
! 5: #include <stdarg.h>
! 6:
! 7: #define KO_TIME_TAB_LEN 10
! 8: #define KO_TIME_NAME_LEN 20
! 9:
! 10: struct ko_time{
! 11: char name[KO_TIME_NAME_LEN];
! 12: clock_t start, end;
! 13: };
! 14:
! 15: struct ko_time ko_time_tab[KO_TIME_TAB_LEN];
! 16:
! 17: static int
! 18: ko_time_getindex(char *s)
! 19: {
! 20: int i;
! 21: for(i=0; i<KO_TIME_TAB_LEN; i++)
! 22: if (!strcmp(ko_time_tab[i].name, s))
! 23: return i;
! 24: fprintf(stderr, "Error: In ko_time_getindex,");
! 25: fprintf(stderr, " unknown name `%s`\n", s);
! 26: exit(EXIT_FAILURE);
! 27: }
! 28:
! 29: void
! 30: ko_time_init(int n, ...)
! 31: {
! 32: va_list ap;
! 33: char *s;
! 34: double *v;
! 35: int i,j;
! 36:
! 37: if (n > KO_TIME_TAB_LEN -1){
! 38: fprintf(stderr, "Error: in ko_time_init\n");
! 39: exit(EXIT_FAILURE);
! 40: }
! 41:
! 42: va_start(ap, n);
! 43: for(i= 0; i<n; i++){
! 44: s = va_arg(ap, char*);
! 45: #ifdef _DEBUG
! 46: fprintf(stderr,"ko_time_tab[%d].name=%s\n",i,s);
! 47: #endif
! 48: if(strlen(s) < KO_TIME_NAME_LEN )
! 49: strcpy(ko_time_tab[i].name, s);
! 50: else{
! 51: fprintf(stderr, "Error: in ko_time_init\n");
! 52: exit(EXIT_FAILURE);
! 53: }
! 54: }
! 55: va_end(ap);
! 56:
! 57: for( ; i<KO_TIME_TAB_LEN; i++)
! 58: strcpy(ko_time_tab[i].name, "");
! 59: }
! 60:
! 61: void
! 62: ko_time_print(void)
! 63: {
! 64: int i,j, len, maxlen=0;
! 65: for(i=0; i<KO_TIME_TAB_LEN; i++)
! 66: if((len = strlen(ko_time_tab[i].name)) > maxlen)
! 67: maxlen = len;
! 68:
! 69: printf("time\n");
! 70: for(i=0; i<KO_TIME_TAB_LEN && (len=strlen(ko_time_tab[i].name)); i++){
! 71: printf("\t%s",ko_time_tab[i].name);
! 72: for(j=len; j<maxlen; j++)
! 73: putchar(' ');
! 74: printf(": %f sec\n", (double)(ko_time_tab[i].end-ko_time_tab[i].start)/CLOCKS_PER_SEC);
! 75: }
! 76: }
! 77:
! 78: void
! 79: ko_time_start(char *s)
! 80: {
! 81: int i = ko_time_getindex(s);
! 82: ko_time_tab[i].start = clock();
! 83: }
! 84:
! 85: void
! 86: ko_time_end(char *s)
! 87: {
! 88: int i = ko_time_getindex(s);
! 89: ko_time_tab[i].end = clock();
! 90: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>