add validate_cost_grad_funct, add timing