//ideally the wrapping would be specified by our @decorator //@execution_time int wield_weapon(int weapon) { //waste time and pretend we're wielding a weapon foreach(int i : weapon){i *= weapon;} return weapon; } closure execution_time(closure func) { closure new_function = function (varargs mixed * args) { int start_time = get_eval_cost(); mixed value = apply(func, args...); /* ideally we have access to details about the function we're wrapping; in python we have good access to these because functions are objects with properties, like a function name, we can access. Then we could say, use something like: sprintf("eval cost for %s: %d\n", function_name(func), eval_cost); */ printf("eval cost: %d\n", start_time - get_eval_cost()); return value; }; return new_function; } mixed test() { /* since we don't have some good syntax help, this is how we simulate it; as you can see, while the basic concept is already something we can use, this is very cumbersome, and we'd have to replace all of the existing calls with something like this to make any use of it. */ return funcall(execution_time(#'wield_weapon), random(10000)); }