是的,Wolfram Workbench 确实有一个分析器,尽管 according to the documentation 的输出不是您想要的形式。
我要注意的是,Mr.Wizard 在 cmets 中提出的问题——缓存的结果会导致不同的计时结果——也可以应用在配置文件中。
如果您只想在 Mathematica 中做某事,您可以尝试以下方法:
myProfile[fun_Symbol,inputs_List]:=
TableForm[#[[{1,3,2}]]&/@ (Join @@@ ({Timing[f[#]],#} & /@ inputs))]
如果您很高兴将输出设为 {timing,output, input},而不是问题中指定的 {timing, input, output},则可以去掉 #[[{1,3,2}]] 位。
编辑
因为我有 Workbench,所以这里有一个例子。我有一个包AdvancedPlots,其中包含一个函数CobwebPlot(是的,函数本身可以改进)。
CobwebPlot[x_?MatrixQ, opts___Rule] /;
And @@ (NumericQ /@ Flatten[x]) :=
Module[{n, \[Theta]s, numgrids, grids, struts, gridstyle, min, max,
data, labels, epilabels, pad},
n = Length[First[x]];
\[Theta]s = (2 \[Pi])/n Range[0, n] + If[OddQ[n], \[Pi]/2, 0];
numgrids =
If[IntegerQ[#] && Positive[#], #,
NumberofGrids /.
Options[CobwebPlot] ] & @ (NumberofGrids /. {opts});
{min, max} = {Min[#], Max[#]} &@ Flatten[x];
gridstyle = GridStyle /. {opts} /. Options[CobwebPlot];
pad = CobwebPadding /. {opts} /. Options[CobwebPlot];
grids =
Outer[List, \[Theta]s, FindDivisions[{0, max + 1}, numgrids]];
struts = Transpose[grids];
labels = CobwebLabels /. {opts} /. Options[CobwebPlot];
epilabels =
If[Length[labels] == n,
Thread[Text[
labels, (1.2 max) Transpose[{Cos[Most[\[Theta]s]],
Sin[Most[\[Theta]s]]}]]], None];
data = Map[Reverse,
Inner[List, Join[#, {First[#]}] & /@ x, \[Theta]s, List], {2}];
Show[ListPolarPlot[grids, gridstyle, Joined -> True, Axes -> False,
PlotRangePadding -> pad],
ListPolarPlot[struts, gridstyle, Joined -> True, Axes -> False],
ListPolarPlot[data,
Sequence @@ FilterRules[{opts}, Options[ListPolarPlot]],
Sequence @@
FilterRules[Options[CobwebPlot], Options[ListPolarPlot]],
Joined -> True, Axes -> None] ,
If[Length[labels] == n, Graphics /@ epilabels,
Sequence @@ FilterRules[{opts}, Options[Graphics]] ]]
]
在调试模式下运行包
然后运行这个笔记本
给出以下输出。