Previous Contents Next


Tracing Function Application

This exercise shows the evaluation of arguments at the moment of function application.
  1. Activate tracing of the function List.fold_left and evaluate the following expression:

    List.fold_left (-) 1 [2; 3; 4; 5];;
    What does the trace show you?

  2. Define the function fold_left_int, identical to List.fold_left, but with type:

    (int -> int -> int) -> int -> int list -> int.
    Trace this function. Why is the output of the trace different?

Performance Analysis

We continue the exercise proposed in chapter 9, page ??, where we compared the evolution of the heap of two programs (one tail recursive and the other not) for calculating primes. This time we will compare the execution times of each function with the profiling tools. This exercise shows the importance of inline expansion (see chapter 7).

  1. Compile the two programs erart and eranrt with profiling options using the bytecode compiler and the native code compiler respectively.

  2. Execute the programs passing them the numbers 3000 4000 5000 6000 on the command line.

  3. Visualize the results with the ocamlprof and gprof commands. What can you say about the results?

Previous Contents Next