Here is the transcript of two sessions: one in Mathematica 9.0 and the other in 10.0:
$ math9
Mathematica 9.0 for Linux x86 (64-bit)
Copyright 1988-2013 Wolfram Research, Inc.
In[1]:= <<ke.m
In[2]:= H[x_,p_,t_]:=p^2/(2*m) + m*omega^2*x^2/2
In[3]:= Timing[kesolve[H,F0]]
p Sin[omega t]
Out[3]= {0.073000, F0[x Cos[omega t] - --------------, p Cos[omega t] + m omega x Sin[omega t]]}
m omega
$ math
Mathematica 10.0 for Linux x86 (64-bit)
Copyright 1988-2014 Wolfram Research, Inc.
In[1]:= <<ke.m
In[2]:= H[x_,p_,t_]:=p^2/(2*m) + m*omega^2*x^2/2
In[3]:= Timing[kesolve[H,F0]]
p Sin[omega t]
Out[3]= {0.793000, F0[x Cos[omega t] - --------------, p Cos[omega t] + m omega x Sin[omega t]]}
m omega
In[4]:= 0.793/0.073
Out[4]= 10.863
In[5]:= !cat ke.m
kesolve[H_,F0_] := Module[{eqn, sol, init, tmp1, tmp2},
(* Store the ODE system of Hamilton's equations and initial conditions in the variable 'eqn' *)
eqn = {x'[t] == (D[H[x,p,t],p]/.{x->x[t],p->p[t]}), p'[t] == -(D[H[x,p,t],x]/.{x->x[t],p->p[t]}), x[0] == x0, p[0] == p0};
(* Try to solve the Cauchy problem for this system *)
sol = DSolve[eqn, {x,p}, t];
(* Verify the solution at a random moment of time *)
tmp1 = eqn /. sol /. {t->RandomReal[]}//Simplify;
If[tmp1 != {{True,True,True,True}}, Return[Print["kesolve: DSolve verification: FAILED"]]];
Clear[tmp1];
(* Express 'initial values' x0,p0 in terms of 'final' values x(t),p(t): x0=x0(x,p,t) and p0=p0(x,p,t) *)
init = Solve[{tmp1 == x[t]/.sol[[1]], tmp2 == p[t]/.sol[[1]]}, {x0,p0}] /. {tmp1->x,tmp2->p} //Simplify;
(* Construct a candidate for the final solution of the Cauchy problem *)
tmp1 = F0[x0/.init[[1]], p0/.init[[1]]];
(* Verify this candidate before returning it *)
tmp2 = D[tmp1,t] + D[H[x,p,t],p]*D[tmp1,x] - D[H[x,p,t],x]*D[tmp1,p]//Simplify;
If[tmp2 =!= 0, Return[Print["kesolve: final solution verification: FAILED"]]];
tmp1
]
As you see, the result is calculated about 11 times faster in Mathematica 9 than in Mathematica 10.
Attachments: