Welcome to mirror list, hosted at ThFree Co, Russian Federation.

iospeed.c « winsup.api « testsuite « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d286f90bd4c49afabb9e252d5498794d7e340bf3 (plain)
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
#include <windows.h>

int verbose = 0;

void
v(char *fmt, ...)
{
  va_list ap;
  if (!verbose) return;
  va_start(ap, fmt);
  vfprintf(stdout, fmt, ap);
  va_end(ap);
}

#define TSIZE (1024 * 1024 * 16)

unsigned long start_tic;

void
start(FILE *f)
{
  fseek(f, 0, SEEK_SET);
  start_tic = GetTickCount();
}

void
end()
{
  unsigned long end_tic = GetTickCount();
  printf("%6d", end_tic - start_tic);
}

void
test(int linesz, int cr)
{
  FILE *f = fopen("iospeed.dat", "wb");
  char buf[65536];
  int i, fd;

  memset(buf, 'x', linesz);
  buf[linesz-1] = '\n';
  if (cr)
    buf[linesz-2] = '\r';
  for (i=0; i<TSIZE; i += linesz)
    fwrite(buf, 1, linesz, f);
  fclose(f);

  f = fopen("iospeed.dat", "rt");
  fd = fileno(f);

  printf("%6d%6d", linesz, cr);
  for (i=0; i<TSIZE; i+= 65536)
    read(fd, buf, 65536);

  start(f);
  while (getc(f) != EOF);
  end();

  start(f);
  while (fread(buf, 1, 256, f) > 0);
  end();

  start(f);
  while (fgets(buf, 64436, f));
  end();

  f = fopen("iospeed.dat", "rb");
  fd = fileno(f);

  for (i=0; i<TSIZE; i+= 65536)
    read(fd, buf, 65536);

  start(f);
  while (getc(f) != EOF);
  end();

  start(f);
  while (fread(buf, 1, 256, f) > 0);
  end();

  start(f);
  while (fgets(buf, 64436, f));
  end();

  printf("\n");
}

int
main(int argc, char **argv)
{
  if (argc > 1 && strcmp(argv[1],"-v") == 0)
    verbose = 1;

  setbuf(stdout, 0);

  printf("              ----- text -----  ---- binary ----\n");
  printf("linesz    cr  getc fread fgets  getc fread fgets\n");

  test(4, 0);
  test(64, 0);
  test(4096, 0);
  test(4, 1);
  test(64, 1);
  test(4096, 1);

  remove ("iospeed.dat");

  return 0;
}