First I generated 100,000 integers and wrote them (one per line) to the file "randomnums.txt".
Using ocaml I wrote a program to read the 100,000 numbers and cube them. It times the time it takes to do that and does it 100 times. Then it takes the average. I ran the program 3 times without linking nums.cmxa or str.cmxa, and 3 times with them.
So in all I read the 100,000 numbers 600 times; 300 times without the libraries, and 300 times with.
I give the results here and then the code. Please note that the numbers the program gives are seconds. In addition, following the program's output, the time command gives the system resources the program used to run. I compiled with -unsafe because I remember seeing in another post that the judging system compiles with it.
Here is without the extra libraries:
Jeff$ ocamlopt -unsafe -o timecubes test.ml
Jeff$ time ./timecubes
0.03027624
real 0m3.040s
user 0m2.894s
sys 0m0.142s
Jeff$ time ./timecubes
0.03027839
real 0m3.037s
user 0m2.894s
sys 0m0.140s
Jeff$ time ./timecubes
0.03028689
real 0m3.038s
user 0m2.894s
sys 0m0.141s
Here is with the extra libraries:
Jeff$ ocamlopt -unsafe -o timecubes str.cmxa nums.cmxa test.ml
Jeff$ time ./timecubes0.03027955
real 0m3.041s
user 0m2.894s
sys 0m0.143s
Jeff$ time ./timecubes
0.03027548
real 0m3.037s
user 0m2.894s
sys 0m0.140s
Jeff$ time ./timecubes
0.03028571
real 0m3.038s
user 0m2.894s
sys 0m0.141s
Jeff$ time ./timecubes
0.03028155
real 0m3.037s
user 0m2.894s
sys 0m0.140s
So there is perhaps an increase in the time it takes to execute the program, but the difference is closer to .00001 second than it is to .01 second. I'll leave it up to you to conclude if this is significant, but it looks like an insignificant amount of time to me.
PS this was run on a 2 ghz intel core duo.
Here's the source code:
(*
store the execution times as a list of type float.
doit reads numbers from the given input channel, which contains 100,000 integers, 1 per line. it calculates the cube of each.
time_doit opens random_nums.txt which contains 100,000 integers, runs doit on the file, then closes it. It puts the time doit took to run on the list, times.
average_time gives the average time of n exections of time_doit
*)
let times = ref [];;
let rec doit ic =
let n = int_of_string (input_line ic) in
ignore(n*n*n);
doit ic;;
let time_doit () =
let inchan = open_in "randomnums.txt" in
let start = Sys.time () in
try
doit inchan;
with _ ->
close_in inchan;
times := (Sys.time () -. start)::(!times);;
let rec average_time = function
0 ->
(List.fold_left
(fun sum a -> sum+.a)
0.0
!times) /. float_of_int (List.length (!times))
| n ->
time_doit ();
average_time (n-1);;
print_endline (string_of_float (average_time 100));
exit 0;
edit - I forgot to close the input channel! It didn't matter, but I had to fix it anyway
It shouldn't change the results in a significant way.