From WikiChip
Difference between revisions of "mirc/optimization"
< mirc

m (if-else vs $iif())
m
Line 6: Line 6:
  
  
== Custom alias bypassing ==
+
== Alias Bypassing ==
 
When calling any form of command or identifer mIRC will attempt to find a scripted version prior to looking for a native equivalent. This functionality can be bypassed by prefixing commands with <code>!</code> and by inserting a <code>~</code> after the <code>$</code> of identifers.
 
When calling any form of command or identifer mIRC will attempt to find a scripted version prior to looking for a native equivalent. This functionality can be bypassed by prefixing commands with <code>!</code> and by inserting a <code>~</code> after the <code>$</code> of identifers.
  
Line 20: Line 20:
  
  
== Conditional Syntax ==
+
== Conditions ==
 
Best to worst:
 
Best to worst:
<syntaxhighlight lang="mirc">if (condition) command
+
<syntaxhighlight lang="mirc">if (condition) command</syntaxhighlight>
if condition { command }
+
<syntaxhighlight lang="mirc">if condition { command }</syntaxhighlight>
if (condition) { command }</syntaxhighlight>
+
<syntaxhighlight lang="mirc">if (condition) { command }</syntaxhighlight>
  
  
 
== if-else vs $iif() ==
 
== if-else vs $iif() ==
$iif() is much slower than using an if-else statement. When $iif() is evaluated it is first rearranged into an if-else statement and the resulting if-else statement is parsed.
+
<code>$iif()</code> is much slower than using an if-else statement. When <code>$iif()</code> is encounter it is first rearranged into an if-else statement and the result is evaluated.
  
 
Best to worst:
 
Best to worst:
Line 45: Line 45:
 
== []'s vs $() vs $eval ==
 
== []'s vs $() vs $eval ==
 
Best to worst:
 
Best to worst:
<syntaxhighlight lang="mirc">[ eval_statement ]
+
<syntaxhighlight lang="mirc">[ eval_statement ]</syntaxhighlight>
$(eval_statement, 2)
+
<syntaxhighlight lang="mirc">$(eval_statement, 2)</syntaxhighlight>
$eval(eval_statement, 2)</syntaxhighlight>
+
<syntaxhighlight lang="mirc">$eval(eval_statement, 2)</syntaxhighlight>

Revision as of 22:25, 15 December 2015


mIRC is not considered a fast language and, more often than not, the easiest implementation is not the fastest.

The following tips will help to increase the execution speed of a script. Most will have a very marginal speed advantage and may not be worth consideration outside of long-running script blocks such as loops.


Alias Bypassing

When calling any form of command or identifer mIRC will attempt to find a scripted version prior to looking for a native equivalent. This functionality can be bypassed by prefixing commands with ! and by inserting a ~ after the $ of identifers.


This bypasses mIRC looking for a scripted echo alias:

!echo -a example1
.!echo -a example2

This bypasses mIRC looking for a scripted me alias1:

echo -a $~me

1: Even though mIRC will use its own native identifers over custom aliases of the same name, there is still some pre-evaluation that can be bypassed using the above method.


Conditions

Best to worst:

if (condition) command
if condition { command }
if (condition) { command }


if-else vs $iif()

$iif() is much slower than using an if-else statement. When $iif() is encounter it is first rearranged into an if-else statement and the result is evaluated.

Best to worst:

var %result = condition_false_value
if (condition) var %result = condition_true_value
if (condition) var %result = condition_true_value
else var %result = condition_false_value
var %result = $iif(condition, condition_true_value, condition_false_value)

/tokenize & $n vs $gettok()

For successive calls against the same data, it is faster to use /tokenize and $n over $gettok().


[]'s vs $() vs $eval

Best to worst:

[ eval_statement ]
$(eval_statement, 2)
$eval(eval_statement, 2)