perftest.pgc
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:3k
- #include <stdio.h>
- #include <sys/time.h>
- #include <unistd.h>
- exec sql include sqlca;
- exec sql whenever sqlerror sqlprint;
- exec sql whenever not found sqlprint;
- static void
- print_result(long sec, long usec, char *text)
- {
- if (usec < 0)
- {
- sec--;
- usec+=1000000;
- }
- printf("I needed %ld seconds and %ld microseconds for the %s test.n", sec, usec, text);
- exec sql vacuum;
- sleep(1);
- }
- int
- main ()
- {
- exec sql begin declare section;
- long i;
- exec sql end declare section;
- struct timeval tvs, tve;
- exec sql connect to mm;
- exec sql create table perftest1(number int4, ascii char(16));
- exec sql create unique index number1 on perftest1(number);
- exec sql create table perftest2(number int4, next_number int4);
- exec sql create unique index number2 on perftest2(number);
- gettimeofday(&tvs, NULL);
- for (i = 0;i < 1407; i++)
- {
- exec sql begin declare section;
- char text[16];
- exec sql end declare section;
- sprintf(text, "%ld", i);
- exec sql insert into perftest1(number, ascii) values (:i, :text);
- exec sql insert into perftest2(number, next_number) values (:i, :i+1);
- exec sql commit;
- }
- gettimeofday(&tve, NULL);
- print_result(tve.tv_sec - tvs.tv_sec, tve.tv_usec - tvs.tv_usec, "insert");
- gettimeofday(&tvs, NULL);
- for (i = 0;i < 1407; i++)
- {
- exec sql begin declare section;
- char text[16];
- exec sql end declare section;
- exec sql select ascii into :text from perftest1 where number = :i;
- exec sql commit;
- }
- gettimeofday(&tve, NULL);
- print_result(tve.tv_sec - tvs.tv_sec, tve.tv_usec - tvs.tv_usec, "selection&projection");
- gettimeofday(&tvs, NULL);
- for (i = 0;i < 1407; i++)
- {
- exec sql begin declare section;
- char text[16];
- exec sql end declare section;
- exec sql select perftest1.ascii into :text from perftest1, perftest2 where perftest1.number = perftest2.number and perftest2.number = :i;
- exec sql commit;
- }
- gettimeofday(&tve, NULL);
- print_result(tve.tv_sec - tvs.tv_sec, tve.tv_usec - tvs.tv_usec, "join");
- gettimeofday(&tvs, NULL);
- exec sql update perftest2 set next_number = next_number + 1;
- exec sql commit;
- gettimeofday(&tve, NULL);
- print_result(tve.tv_sec - tvs.tv_sec, tve.tv_usec - tvs.tv_usec, "update");
- gettimeofday(&tvs, NULL);
- exec sql delete from perftest2;
- exec sql commit;
- gettimeofday(&tve, NULL);
- print_result(tve.tv_sec - tvs.tv_sec, tve.tv_usec - tvs.tv_usec, "delete");
- exec sql drop index number2;
- exec sql drop table perftest2;
- exec sql drop index number1;
- exec sql drop table perftest1;
- exec sql commit;
- exec sql disconnect;
- return (0);
- }