If you control the code, the easiest way is to : - add runtime profiling functions directly inside the generated code (for example, one before each function call and sequencing construct) - hardcode into your profiling functions the fact that, after a certain number of steps, excecution should be aborted. Example : let count = ref 0 let max_count = 100 (* you choose that constant during generation *) exception Terminated let step () = incr count; if !count > max_count then raise Terminated (* generated code *) let code () = ... ; step (); ...; step () ; ... You could probably also have max_count passed as a parameter at execution time (allowing you to execute the same generated code with different time limits).