1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/******** CALCULATE I/O PERFORMANCE TO NUL FILE ********/
#include <assert.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#define CHK 100 /* speed factor */
long ticks(long tick) /* GET BIOS TIME TICK */
{
union REGS reg;
reg.h.ah=0;
int86(0x1A, ®, ®);
return ((long)reg.x.cx<<16)+reg.x.dx-tick;
}
long time_it(void(*func)(void))
{
long t = ticks(0L);
(*func)();
return ticks(t);
}
void show_it(long t)
{
long lquot, lrem;
t = (t*1000/182+5)/10;
lquot = t/10;
lrem = t%10;
printf("%3ld.%02d sec", lquot, (int)lrem);
}
void t_printf(void)
{
register FILE *fp;
register unsigned u;
fp = fopen("NUL", "wt");
assert(fp != NULL);
for (u=0; u<50*CHK; ++u)
fprintf(fp, "Now is %d time for %d little indians\n", 123, -456);
fclose(fp);
}
void b_printf(void)
{
register FILE *fp;
register unsigned u;
fp = fopen("NUL", "wb");
assert(fp != NULL);
for (u=0; u<50*CHK; ++u)
fprintf(fp, "Now is %d time for %d little indians\n", 123, -456);
fclose(fp);
}
void tu_printf(void)
{
register FILE *fp;
register unsigned u;
fp = fopen("NUL", "wt");
assert(fp != NULL);
setbuf(fp, NULL);
for (u=0; u<5*CHK; ++u)
fprintf(fp, "Now is %d time for %d little indians\n", 123, -456);
fclose(fp);
}
void bu_printf(void)
{
register FILE *fp;
register unsigned u;
fp = fopen("NUL", "wb");
assert(fp != NULL);
setbuf(fp, NULL);
for (u=0; u<5*CHK; ++u)
fprintf(fp, "Now is %d time for %d little indians\n", 123, -456);
fclose(fp);
}
void t_write(void)
{
register FILE *fp;
register unsigned u;
fp = fopen("NUL", "wt");
assert(fp != NULL);
for (u=0; u<250*CHK; ++u)
fwrite("Now is the time for all good men to come\n", 41, 1, fp);
fclose(fp);
}
void b_write(void)
{
register FILE *fp;
register unsigned u;
fp = fopen("NUL", "wb");
assert(fp != NULL);
for (u=0; u<500*CHK; ++u)
fwrite("Now is the time for all good men to come\n", 41, 1, fp);
fclose(fp);
}
void tu_write(void)
{
register FILE *fp;
register unsigned u;
fp = fopen("NUL", "wt");
assert(fp != NULL);
setbuf(fp, NULL);
for (u=0; u<100*CHK; ++u)
fwrite("Now is the time for all good men to come\n", 41, 1, fp);
fclose(fp);
}
void bu_write(void)
{
register FILE *fp;
register unsigned u;
fp = fopen("NUL", "wb");
assert(fp != NULL);
setbuf(fp, NULL);
for (u=0; u<200*CHK; ++u)
fwrite("Now is the time for all good men to come\n", 41, 1, fp);
fclose(fp);
}
main(void)
{
show_it(time_it(t_printf));
printf(": time for text printf buffered\n");
show_it(time_it(b_printf));
printf(": time for binary printf buffered\n");
show_it(time_it(tu_printf));
printf(": time for text printf unbuffered\n");
show_it(time_it(bu_printf));
printf(": time for binary printf unbuffered\n");
show_it(time_it(t_write));
printf(": time for text write buffered\n");
show_it(time_it(b_write));
printf(": time for binary write buffered\n");
show_it(time_it(tu_write));
printf(": time for text write unbuffered\n");
show_it(time_it(bu_write));
printf(": time for binary write unbuffered\n");
return 0;
}
|