3
$\begingroup$

I want to know how long each VerificationTest took to complete in the test report, so see which one was the longest and do some statistics on them:

TestReport[
 Table[VerificationTest[
   FullSimplify[2 Sin[12 x + 15 y] Cos[14 x + 21 y]], 
   Simplify[2 Sin[12 x + 15 y] Cos[14 x + 21 y]]], {10}]]
$\endgroup$
6
+50
$\begingroup$

The most straightforward method seems to be to map the test property you are looking for over the TestReportObject, as follows:

report = TestReport[{VerificationTest[Limit[Exp[t], t -> 0], 2], 
  VerificationTest[PrimeQ[7]],
  VerificationTest[Factor[1 - 2 x + x^2], (x + 1)^2],
  VerificationTest[Infinity - Infinity, Indeterminate]}];

Map[#["AbsoluteTimeUsed"] &]@report["TestResults"]
(* 
 <|1 -> Quantity[0.029815, "Seconds"], 
   2 -> Quantity[0.000135, "Seconds"], 
   3 -> Quantity[0.000217, "Seconds"], 
   4 -> Quantity[0.001597, "Seconds"]|>
*)

An alternative, is to use Query:

Query[All, (#["AbsoluteTimeUsed"] &)]@report["TestResults"]

which produces identical results. It is more verbose than Map, but it is potentially cleaner.


The cleanest method, as pointed out by Ilian, is to use Through, e.g.

Through[Values[report["TestResults"]]["AbsoluteTimeUsed"]]

even though it is not the shortest character wise.

$\endgroup$
  • 1
    $\begingroup$ I concur that this is the best way to do this. $\endgroup$ – Stefan R Jul 7 '15 at 20:08
  • $\begingroup$ The #[]&/@ syntax isn't the prettiest. $\endgroup$ – M.R. Jul 7 '15 at 23:23
  • $\begingroup$ It's not, but I found one with Query. Will add it. $\endgroup$ – rcollyer Jul 8 '15 at 1:07
  • 1
    $\begingroup$ For just the timings (and prettier syntax), maybe Through[Values[report["TestResults"]]["AbsoluteTimeUsed"]]. $\endgroup$ – ilian Jul 8 '15 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.