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
WHO WANTS TO PLAY AMONG US
Elza [17]

Answer:

Explanation:

ME

8 0
3 years ago
Read 2 more answers
Your app needs to store the following information. For each type of information, decide whether you would use an array or a vari
Virty [35]

Answer:

Array: (a) All the messages a user has sent.

Variable: (b) The highest score a use has reached on the app. (c) A username and password to unlock the app.

Explanation:

An array generally has more than one value whereas a variable can only contain a single value at any particular point in time. In addition, a variable has a limit whereas an array does not have any maximum limit. Therefore, it can be concluded that option (a) will be stored as an array while options (b) and (c) will be stored as variables.

3 0
3 years ago
What keyboard key can you press to limit the angle of the line when using the pencil tool?
leva [86]
F6,p hope that helps :)
6 0
3 years ago
Assume that an array of Integers named a that contains exactly five elements has been declared and initialized. In addition, an
just olya [345]

Complete Question:

Assume that an array of Integers named a that contains exactly five elements has been declared and initialized. In addition, an int variable j has also been declared and initialized to a value somewhere between 0 and 3.

Write a single statement that assigns a new value to the element of the array indexed by j. This new value should be equal to twice the value stored in the next element of the array (i.e. the element after the element indexed by j ). Do not modify any other elements of the array!

Answer:

a[j] = 2 * a[j+1];

Explanation:

Since the array is named a and its indexes are referenced by the variable j

it means the elements of the array will be a[j] for (j=0; j=1;j=2).

The first element in the array (j=0) will be a[0], second element will be a[1] and so on.

The statement a[j] = 2 * a[j+1]; assigns a new value to the element of the array indexed by j, the  value is equal to twice the value stored in the next element of the array (j+1).

4 0
3 years ago
Gemima has converted her table to a clustered column
Ber [7]

Answer:

1. Select the table

2. use Ctrl A

3. type the title

3 0
3 years ago
Other questions:
  • Can your computer become infected with a virus via email
    10·1 answer
  • Refer to the following code segment. You may assume that array arr1 contains elements arr1[0],arr[1],...,arr[N-1], where N = arr
    8·1 answer
  • The World Wide Web Consortium enforced a stricter set of standards in a different version of Hypertext Markup Language (HTML) ca
    7·1 answer
  • In an MLA style citation for an image, what information should be listed first? A. The name of the creator B. The title of the i
    8·2 answers
  • How do you calculate the life span of patents?
    13·1 answer
  • PLZ ANSWER ALL MY QUESTION. Which line of code will display the variable num rounded to the nearest tenth?
    14·1 answer
  • Which of the following ""invisible"" marks represents an inserted tab?
    10·1 answer
  • Do you know how to change your grades on a printer???????????
    13·1 answer
  • A serial schedule:
    8·1 answer
  • If you need assistance or have questions related to your sevis record, i-20, admission, or course registration which phone numbe
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!