Module:Timing/doc: Difference between revisions

Content deleted Content added
Hot Pork Pie (talk | contribs)
"reverted possible vandalism"
Line 31:
</source>
 
A call like that produced for the same type of module a report like the following at enwikinowiki
 
<pre>
=require 'Module:Timing'(p.hello,1000,100)
Each call was running for about 86.5120000000022E20966E-9 seconds. Mean runtimerun time for each set was 86.5120000000022E20966E-76 seconds,
with a standard deviation of 15.2400753202931E6091767397007E-6 seconds, minimum 1.2962E-5, maximum 1.5542E-5. Total time spent was about 0.00038879010717389 seconds.
</pre>
 
In this the important information is <tt>Each call was running for about 8.5120000000022E-9 seconds</tt>. This says how long the function actually run.
 
Note that this function is very simple, and therefore the run time for the function gets close to the run time for the baseline. As a result the run time for each set gets close to the standard deviation.
 
If a call need some parameters, then those most be provided in a wrapper function. That can be achieved by adding a separate function like the following, and then timing the resulting function
 
<source lang="Lua">
function wrap() return p.hello(mw.getCurrentFrame()) end
=require 'Module:Timing'(wrap)
</source>
 
A call sequence like that produced the following output
 
<pre>
function wrap() return p.hello(mw.getCurrentFrame()) end
=require 'Module:Timing'(wrap)
Each call was running for about 3.48499E-7 seconds. Mean runtime for each set was 3.48499E-5 seconds,
with standard deviation of 1.1898648017737E-5 seconds,
minimum 8.9850000000004E-6, maximum 1.0064E-5. Total time spent was about 0.000585205 seconds.
</pre>
 
Sometimes it is better to put the wrapper in the module under inspection itself
 
<source lang="Lua">
my_object = {};
 
my_object.hello = function( frame )
local str = "Hello World!"
return str
end
 
my_object.wrap = function ()
return my_object.hello(mw.getCurrentFrame())
end
 
return my_object
</source>
 
That produced the following output
 
<pre>
=require 'Module:Timing'(p.wrap)
Each call was running for about 1.91509E-7 seconds. Mean runtime for each set was 1.91509E-5 seconds,
with standard deviation of 7.6705200899287E-6 seconds,
minimum 4.5409999999994E-6, maximum 4.937E-6. Total time spent was about 0.000318969 seconds.
</pre>
 
Even simple wrappers will take a lot of time. Even if we drop getting the current frame in the previous timing calls the run time is still 10 times higher than the bare call.
 
The morale is; do not add wrappers to very simple functions, the numbers will be far off! ;)
 
==Gadget==