1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
suter [353]
3 years ago
13

Implement a program to measure the impact of application-level buffer sizes on read time. This involves writing to and reading f

rom a large file (say, 2 GB). Vary the application buffer size (say, from 64 bytes to 4 KB). Use timing measurement routines (such as gettimeofday and getitimer on UNIX) to measure the time taken for different buffer sizes. Analyze the results and report your findings: does buffer size make a difference to the overall write time and per-write time?

Computers and Technology
1 answer:
Luda [366]3 years ago
6 0

Answer:

Input file: input.txt

Output file: output.txt

input.txt is a text file of 500 MB.

CODE:

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

#include <fcntl.h>

#include <sys/time.h>

#include <string.h>

#include <unistd.h>

#include <sys/types.h>

double count = 0; // to keep the count of writes

// function which reads from input.txt and writes to output.txt

void fun(int* file_in, int* file_out, int BUFF_SIZE)

{

char *buff = (char *)malloc(BUFF_SIZE*sizeof(char));

while(read(*file_in, buff, BUFF_SIZE) != 0)

{

write(*file_out, buff, strlen(buff));

count++;

}

}

int main(int argc, char* argv[])

{

if(argc == 1)

{

printf("Usage: ./program.c [ buff_size(in bytes) ]\n");

return 0;

}

int file_in,file_out; // input and output file pointers

file_in = open("input.txt",O_RDONLY);

if(file_in == -1)

{

printf("Error while open input.txt \n");

return 0;

}

file_out = open("output.txt",O_WRONLY);

if(file_out == -1)

{

printf("Error occured while opening output.txt\n");

return 0;

}

struct timeval t1, t2; // for capture time

double elapsedTime;

// start timer

gettimeofday(&t1, NULL);

// do something

// ...

fun(&file_in, &file_out, atoi(argv[1]));

// stop timer

gettimeofday(&t2, NULL);

// compute and print the elapsed time in millisec

elapsedTime = (t2.tv_sec - t1.tv_sec)*1000.0; // sec to ms

printf("Overall write time: %lf ms\n",elapsedTime);

printf("Per write time: %lf ms\n", elapsedTime/count);

return 0;

Explanation:

Please see attachment for output

You might be interested in
This is an example of what type of formula?
Dimas [21]

Answer:

Subtraction

Explanation:

That is subtracting the values of two cells.

You know because of the "-" sign

4 0
2 years ago
Which would be the most appropriate way to estimate -6.1(0.22)? Check all that apply.
Sergeu [11.5K]

Answer:

A.Use rounding to get -6(0.2), and then multiply. and D. use front end estimation to get -6(0.2), and multiply. and B.

Explanation:

just took the test

7 0
3 years ago
Read 2 more answers
How many 32 bit integers can be stored in 16 byte cache block in matlab?
Sladkaya [172]
Bytes have eight bits. 32 bits would be four bytes.
4 0
3 years ago
For each of the innovations below. Decide if it is a computing innovation or not. Part 3 Continued.
stira [4]

Explanation:

a table of the chemical elements arranged in order of atomic number, usually in rows, so that elements with similar atomic structure (and hence similar chemical properties) appear in vertical columns.

6 0
3 years ago
Select the items that can be measured.
Slav-nsk [51]

Answer:

distance

capacity

smoothness

thickness

4 0
3 years ago
Read 2 more answers
Other questions:
  • Which character must decide whether to support the assassins or avenge his friend's death?
    14·2 answers
  • What is the primary purpose for a screen saver in windows?
    8·1 answer
  • Please help
    5·1 answer
  • list six external parts or peripherals of a computer system and identify which are output and which are input devices
    8·1 answer
  • David Doe is a network administrator for the ABC Company. David is passed over for promotion three times. He is quite vocal in h
    14·1 answer
  • The moon has less mass than the earth, so what happens to objects on the moon?
    11·1 answer
  • How do you increase the number of tries by one?
    10·1 answer
  • Imma say something random...
    13·2 answers
  • HELP<br> When differentiating data, the WHAT of the data is:
    11·1 answer
  • Edit the following statement so it uses the constant named YEAR:
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!