Tuesday, 31 January 2017

Performance test case in radix tree __alloc_fd

This is the performance test case. It is used to check the time taken to do several allocation and deallocation of the file descriptors.
This test performs below steps: 
 * Open 1000 file
 * Close 20 files
 * Open 20 files again.
 * Repeat step 2
Upon successful execution, this program will return zero and print the time taken by the program on the terminal.


 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
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv)
{

 int fd[1000], nfd[20];
 int i, j, rfd[20], cnt = 1000;
 char buf[15];
 int err = 0;
 int opt, nloop = 100000;
 clock_t start, end;
 double time_taken;
 unsigned int seed = time(NULL);
 
 while ((opt = getopt(argc, argv, s:l:)) != -1)
 {
 switch (opt) {
 case s:
 seed = atoi(optarg);
 printf(seed = %d\n,seed);
 break;
 case l:
 nloop = atoi(optarg);
 printf(nloop = %d\n,nloop);
 break;
 }
 }
 
 for(i = 0; i < 1000; i++)
 {
  sprintf(buf, test/myfile%d, i);
  fd[i] = open(buf, O_CREAT | O_RDWR, 0644);
 
 if(fd[i] == -1)
 {
  err = errno;
  cnt = i;
  goto out;
 }
 }
 
 
 srand(seed);
 start = clock(); /* start time */
 for(i = 0; i < nloop; i++)
 {
 /* Close any 20 files randomly */
 for(j = 0; j < 20; j++)
 {
  rfd[j] = rand() % 1000+3;
  err = close(rfd[j]);
 if(err == -1)
 {
 if(errno == EBADF)
  j  ;
 else
  abort();
 }
 }

/* Open 20 files which are closed by above loop */
 for(j = 0; j < 20; j++)
 {
  sprintf(buf, test/myfile%d,rfd[j]);
  nfd[j] = open(buf, O_CREAT | O_RDWR, 0644);
 if(nfd[j] < 0)
 {
  err = errno;
  goto out;
 }
 }
 }
 
 end = clock(); /* end time */
 time_taken = ((double) (end  start)) / CLOCKS_PER_SEC;
 printf(This program took %f seconds to execute\n,time_taken);
 printf(Time taken by per file descriptor opened-closed : %.2f microsecond\n,
 (time_taken/(nloop*20))*1000000);
out:
 for(i = 0; i < cnt; i++)
 {
  sprintf(buf, test/myfile%d,i);
  unlink(buf);
 }
 return err;
}


I have taken below reading for above test case ,
Performance numbers are as below :



 



 

No comments:

Post a Comment