To build the solution, run make ex13_1
.
The command options are:
- -b block_size - sets the size of the input buffer
- -s - enables the O_SYNC flag when opening the output file
- -v - shows more detailed output
- input file name
- output file name
To generate a log file of multiple runs, do
./test_ex13_1.sh >>test_run_2020_02_20.log
Output file has the following fields:
- Block Size
- Synchronisation flag set?
- Number of bytes read
- Wall clock time in seconds
- User time in seconds
- System time in seconds
$ ./ex13_1 -b 512 /tmp/ex13_1.in /tmp/ex13_1.out
512 - 67108864 0.28 0.07 0.21
$ ./ex13_1 -b 65536 /tmp/ex13_1.in /tmp/ex13_1.out
65536 - 67108864 0.09 0.00 0.08
Note The fourth column (Wall clock time) appears not to match the output from time
.
Increasing the internal buffer size from 512 to 65536 (64K) reduced the overall time (user + sys) from 0.21s to 0.08s (a 62% reduction).
$ ./ex13_1 -b 65536 -s /tmp/ex13_1.in /tmp/ex13_1.out
65536 s 67108864 0.41 0.00 0.40
$ ./ex13_1 -b 512 -s /tmp/ex13_1.in /tmp/ex13_1.out
512 s 67108864 27.10 1.51 25.59
Note The actual elapsed time for the 512 byte buffer case was several hours (not 27 seconds).
Adding O_SYNC
significantly increasing the run time (but the effect is much less with larger internal buffers).
Not done yet.
To compile the solution, run:
make ex13_2
To execute the solution, run:
./ex13_2 -b 4096 -f -d -n 409600 test.dat
Sample output is:
4096 - f d 409600 0.04 0.00 0.03
Refer to Ex13-3.md
To compile the solution, run:
make ex13_4
To execute the solution, run:
./ex13_4
The expected output is:
If I had more time,
I would have written you a shorter letter.
To run the solution with a file, run:
./ex13_4 >test.dat
cat test.dat
The expected output is:
I would have written you a shorter letter.
If I had more time,
To compile the solution, run:
make my_tail
To execute the solution, run:
./my_tail -n 2000 results.csv | wc -l
The expected output is:
2000