Content deleted Content added
m Typo fixing, replaced: occurences → occurrences, typo(s) fixed: As a result → As a result,, ie. → i.e. , stripped down → stripped-down |
mNo edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 15:
=== Testing a plain function ===
For example, assume we open a page [[Module:
The following code is a stripped-down version of [[Module:
<
local str = "Hello World!"
return str
end
return
</syntaxhighlight>
Access to this code will be through a generic ''p'' in the debug console. Assuming the previous code the profiler can be called as
<
=require 'Module:Timing'(p.hello)
</syntaxhighlight>
A call like that produced for the same type of module a report like the following at enwiki
Line 57:
A common example on how to pass in an argument is how to do this for the current frame
<
=require 'Module:Timing'(p.hello, mw.getCurrentFrame())
</syntaxhighlight>
This produce the following output
Line 83:
The wrapper function can de defined in the debugger, that is added in the text area for debugging. Add a separate function like the following
<
function wrap() return p.hello(mw.getCurrentFrame()) end
=require 'Module:Timing'(wrap)
</syntaxhighlight>
A call sequence like that produced the following output
Line 105:
An alternate form with an anonymous function is
<
=require 'Module:Timing'(function() return p.hello(mw.getCurrentFrame()) end)
</syntaxhighlight>
In general you should precompute as much as possible to avoid unnecessary computations inside the loop, like this
<
my_frame=mw.getCurrentFrame()
=require 'Module:Timing'(function() return p.hello(my_frame) end)
</syntaxhighlight>
====Wrapper in the module====
Sometimes it is better to put the wrapper in the module itself
<
my_object = {};
Line 131:
return my_object
</syntaxhighlight>
That produced the following output
Line 148:
In general you should precompute as much as possible to avoid unnecessary computations inside the loop, like this
<
my_object = {};
Line 162:
return my_object
</syntaxhighlight>
===Testing in a sandboxed environment===
Line 169:
Sometimes it is better to put the wrapper in the module under inspection itself
<
local timing = require 'Module:Timing'
Line 184:
return my_object
</syntaxhighlight>
This can them be used in [[Special:TemplateSandbox]] with a prefix from [[Special:MyPage/sandbox]] and any "render page" we see fit for the purpose. Often we want a specific page though to get access to additional data like the Wikidata item. Fill inn an invoke-call for our helper function
<
{{#invoke|HelloWorld|TIMING}}
</syntaxhighlight>
and we will have a timing report for the helper call in the module.
|