(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 5483, 204]*) (*NotebookOutlinePosition[ 6180, 228]*) (* CellTagsIndexPosition[ 6136, 224]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Speed comparison of a function with its Compiled version.", "Title"], Cell["\<\ First lets check to make sure both are giving the same results:\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(SameQ[ SplitStep`Private`ExpFourierD2Vector[1. , 120, 1. ]\ - \ SplitStep`Private`CompiledExpFourierD2Vector[1. , 120, 1. ]]\)], "Input", CellLabel->"In[9]:="], Cell[BoxData[ \(True\)], "Output", CellLabel->"Out[9]="] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Timing[\(SplitStep`Private`ExpFourierD2Vector[1. , 120, 1. ];\)]\)], "Input", CellLabel->"In[10]:="], Cell[BoxData[ \({0.`\ Second, Null}\)], "Output", CellLabel->"Out[10]="] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Timing[\(SplitStep`Private`CompiledExpFourierD2Vector[1. , 120, 1. ];\)] \)], "Input", CellLabel->"In[11]:="], Cell[BoxData[ \({0.`\ Second, Null}\)], "Output", CellLabel->"Out[11]="] }, Open ]], Cell["\<\ At this size, both are too fast to even see how long they take. A quick way \ to increase the time is to loop:\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Timing[ Do[Length[SplitStep`Private`ExpFourierD2Vector[1. , 120, 1. ]], {1000}]] \)], "Input", CellLabel->"In[12]:="], Cell[BoxData[ \({3.740000000000009`\ Second, Null}\)], "Output", CellLabel->"Out[12]="] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Timing[ Do[Length[SplitStep`Private`CompiledExpFourierD2Vector[1. , 120, 1. ]], {1000}]]\)], "Input", CellLabel->"In[13]:="], Cell[BoxData[ \({0.2699999999999818`\ Second, Null}\)], "Output", CellLabel->"Out[13]="] }, Open ]], Cell["\<\ Adding Do becomes tedious when you have to figure out about the number of \ times to loop to get a decent timing. An alternate way of doing this is to \ define a command which does it for you:\ \>", "Text"], Cell[BoxData[{ \(\(SetAttributes[time, \ HoldAll];\)\), "\[IndentingNewLine]", \(time[expr_]\ := \ \((Block[{Second\ = \ 1}, Module[{t\ = \ \(Timing[\(expr;\)]\)[\([1]\)], \ tries\ = \ 1}, \[IndentingNewLine]While[t\ < \ 1. , \ tries\ *= \ 2; \ t\ = \ \(Timing[Do[expr, \ {tries}]]\)[ \([1]\)]]; \[IndentingNewLine]t/tries]]\ Second)\)\)}], "Input", CellLabel->"In[14]:="], Cell[CellGroupData[{ Cell[BoxData[ \(time[SplitStep`Private`ExpFourierD2Vector[1. , 120, 1. ]]\)], "Input", CellLabel->"In[16]:="], Cell[BoxData[ \(0.0036328125000000266`\ Second\)], "Output", CellLabel->"Out[16]="] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(time[SplitStep`Private`CompiledExpFourierD2Vector[1. , 120, 1. ]]\)], "Input", CellLabel->"In[17]:="], Cell[BoxData[ \(0.00028320312499999223`\ Second\)], "Output", CellLabel->"Out[17]="] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(time[SplitStep`Private`CompiledExpFourierD2Vector[1. , 8192, 1. ]]\)], "Input", CellLabel->"In[18]:="], Cell[BoxData[ \(0.018124999999999503`\ Second\)], "Output", CellLabel->"Out[18]="] }, Open ]], Cell["Now lets see what the caching does for us:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(SplitStep`Private`ClearD2Cache; time[SplitStep`Private`CachedD2Vector[1. , 120, 1. ]]\)], "Input", CellLabel->"In[19]:="], Cell[BoxData[ \(4.615783691406389`*^-6\ Second\)], "Output", CellLabel->"Out[19]="] }, Open ]], Cell[BoxData[ \(DownValues[SplitStep`Private`CachedD2Vector]\)], "Input", CellLabel->"In[20]:="], Cell["This clears the cache again.", "Text"], Cell[BoxData[ \(\(SplitStep`Private`ClearD2Cache;\)\)], "Input", CellLabel->"In[21]:="] }, Open ]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 695}}, WindowSize->{496, 599}, WindowMargins->{{229, Automatic}, {Automatic, 32}}, StyleDefinitions -> "ArticleClassic.nb" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1739, 51, 74, 0, 150, "Title"], Cell[1816, 53, 87, 2, 27, "Text"], Cell[CellGroupData[{ Cell[1928, 59, 200, 5, 91, "Input"], Cell[2131, 66, 62, 2, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[2230, 73, 125, 3, 51, "Input"], Cell[2358, 78, 78, 2, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[2473, 85, 137, 3, 71, "Input"], Cell[2613, 90, 78, 2, 30, "Output"] }, Open ]], Cell[2706, 95, 135, 3, 44, "Text"], Cell[CellGroupData[{ Cell[2866, 102, 151, 4, 71, "Input"], Cell[3020, 108, 93, 2, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[3150, 115, 161, 4, 91, "Input"], Cell[3314, 121, 94, 2, 30, "Output"] }, Open ]], Cell[3423, 126, 216, 4, 61, "Text"], Cell[3642, 132, 484, 10, 151, "Input"], Cell[CellGroupData[{ Cell[4151, 146, 115, 2, 31, "Input"], Cell[4269, 150, 89, 2, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4395, 157, 126, 3, 51, "Input"], Cell[4524, 162, 90, 2, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4651, 169, 127, 3, 51, "Input"], Cell[4781, 174, 88, 2, 30, "Output"] }, Open ]], Cell[4884, 179, 58, 0, 27, "Text"], Cell[CellGroupData[{ Cell[4967, 183, 148, 3, 51, "Input"], Cell[5118, 188, 89, 2, 30, "Output"] }, Open ]], Cell[5222, 193, 102, 2, 31, "Input"], Cell[5327, 197, 44, 0, 27, "Text"], Cell[5374, 199, 93, 2, 31, "Input"] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)