Format Comparison

From ComputingForScientists

Jump to: navigation, search

HW #4

Based on topics covered in Introduction_to_the_Shell#Bash, IO#Speed_Comparison, and RDMS.

1. Format Comparison

Consider a data set which is a list of 105 integers stored in a file. The integers have values between 0 and 216-1.

The use-case under consideration is that a user wants to specify an integer and have the count of the number of integers in the file that match displayed on the screen.

In this problem, you will consider different methods for implementing a program to do this task.

Part I

  1. Write a program that creates an ASCII file containing 105 values and displays how long it took to write the file (Save program in file named HW4a.?, where ? depends on the language the program was written in.)
  2. Write a program that creates a binary file containing the same 105 values as the previous question and displays how long it took to write the file. (Save program in file named HW4b.?, where ? depends on the language the program was written in.)
  3. Write a program that creates an SQL file with commands that will generate a table with the same 105 values as the previous question and displays how long it took to write the file. Write a Bash command that creates a sqlite3 database using this SQL file and displays how long it took to execute the command. (Save program in file named HW4c.?, where ? depends on the language the program was written in. Save Bash command in a file named HW4c.sh.)


Part II

  1. Write set of Bash commands that displays the count of the number of values in the ASCII file and displays how long it took to finish (using the Bash command time). (Save command in file named HW4d.sh)
  2. Write a program that reads the ASCII file and displays the number of values and displays how long it took to finish. (Save program in file named HW4e.?, where ? depends on the language the program was written in.)
  3. Write a program that reads the binary file and displays the number of values and displays how long it took to finish. (Save program in file named HW4f.?, where ? depends on the language the program was written in.)
  4. Write a Bash command executes a SQL query of the database using sqlite3 and displays the number of values and displays how long it took to finish. For example, entering on the Bash command line sqlite3 astro.db "select * from ASTRO;", would be the same as entering select * from ASTRO; on the sqlite3 command line after starting it with sqlite3 astro.db. (Save command in file named HW4g.sh)

2. Extra Credit

Modify the program HW4.m so that the same tests made for c are made for any one of the following programs: Java, Python, C++ or Fortran 77 or 90. Note that the c program outputs timing information as a list of comma separated values printed to stdout (the screen) that are read and parsed in MATLAB. To test your program, use the following MATLAB/Octave program and verify that the variable R contains a list of 5 numbers. Sample "Hello World" codes are available at [2]. See also [3].

% You may need to install gfortran on your virtual machine using
% sudo apt-get install gfortran
system('gfortran HW4.f -o HW4');
[s,result] = system('./HW4');
R = textscan(result,'%s%s%s%s%s','delimiter',',')

[s,result] = system('python HW4.py');
R = textscan(result,'%s%s%s%s%s','delimiter',',')

system('javac HW4.java');
[s,result] = system('java HW4');
R = textscan(result,'%s%s%s%s%s','delimiter',',')

Upload your code to your BitBucket repository. After checking out your code, I should be able to start MATLAB and enter HW5EC on the command line and see the timing results.

Personal tools