Skip to content

Commit

Permalink
fix open close bench
Browse files Browse the repository at this point in the history
  • Loading branch information
WilyTiger committed Sep 25, 2024
1 parent b64a8f6 commit ab677ed
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cloud/filestore/tools/testing/open_close_bench/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {

char filename[100];
int fds[100000];
clock_t startTime, endTime;
struct timespec startTime, endTime;
double openTime, closeTime;

for (int i = 0; i < n; i++) {
Expand All @@ -52,25 +52,25 @@ int main(int argc, char *argv[]) {
}

// Measure opening latency
startTime = clock();
clock_gettime(CLOCK_MONOTONIC, &startTime);
for (int i = 0; i < n; i++) {
snprintf(filename, sizeof(filename), "file%d.txt", i + 1);
fds[i] = open(filename, O_RDONLY);
}
endTime = clock();
clock_gettime(CLOCK_MONOTONIC, &endTime);

openTime = ((double)(endTime - startTime)) / CLOCKS_PER_SEC;
openTime = (endTime.tv_sec - startTime.tv_sec) + (endTime.tv_nsec - startTime.tv_nsec) / 1e9;
printf("Open %.6f ms\n", openTime * 1000);
printf("Open avg %.6f ms\n", openTime * 1000 / n);

// Measure closing latency
startTime = clock();
clock_gettime(CLOCK_MONOTONIC, &startTime);
for (int i = 0; i < n; i++) {
close(fds[i]);
}
endTime = clock();
clock_gettime(CLOCK_MONOTONIC, &endTime);

closeTime = ((double)(endTime - startTime)) / CLOCKS_PER_SEC;
closeTime = (endTime.tv_sec - startTime.tv_sec) + (endTime.tv_nsec - startTime.tv_nsec) / 1e9;
printf("Close %.6f ms\n", closeTime * 1000);
printf("Close avg %.6f ms\n", closeTime * 1000 / n);

Expand Down

0 comments on commit ab677ed

Please sign in to comment.