<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/10180" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2009-02-10T07:45:26-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/10180</id>

		<entry>
		<author><name><![CDATA[MrStonedOne]]></name></author>
		<updated>2009-02-10T07:45:26-04:00</updated>

		<published>2009-02-10T07:45:26-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=87329#p87329</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=87329#p87329"/>
		<title type="html"><![CDATA[if and set]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=87329#p87329"><![CDATA[
im not sure how faster this is... but remember, the set command returns what was just set on something. so <div class="codebox"><p>Code: </p><pre><code>if {[set nick [hand2nick $::owner]] == "blah"} putlog "$nick"</code></pre></div>is faster then <div class="codebox"><p>Code: </p><pre><code>if {[hand2nick $::owner] == "blah"} putlog "[hand2nick $::owner]"</code></pre></div>and as you see here... using ::varName is faster for accessing globals then to map it with the global command (unless your gonna be accessing a global alot in one proc. then the command is faster)<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8744">MrStonedOne</a> — Tue Feb 10, 2009 7:45 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[sKy]]></name></author>
		<updated>2005-08-13T20:45:52-04:00</updated>

		<published>2005-08-13T20:45:52-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=54217#p54217</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=54217#p54217"/>
		<title type="html"><![CDATA[Tcl performance, script optimization]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=54217#p54217"><![CDATA[
If you want to use the return code from a command/proc serval times i suggest you to use the set command and not to execute it each time.<br><br>Examples (just to show you what i mean):<br>- slow:<div class="codebox"><p>Code: </p><pre><code>proc te10 { } {putlog "te10: [hand2nick $::owner]"putlog "te10: [hand2nick $::owner]"putlog "te10: [hand2nick $::owner]"}</code></pre></div>- faster:<div class="codebox"><p>Code: </p><pre><code>proc te10 { } {set ownerhand [hand2nick $::owner]putlog "te10: $ownerhand"putlog "te10: $ownerhand"putlog "te10: $ownerhand"}</code></pre></div>Very second i might add, in my personal opinion a script looks more easy and clear if you use the set command more often then executing all this stuff over and over again.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=6101">sKy</a> — Sat Aug 13, 2005 8:45 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[demond]]></name></author>
		<updated>2005-08-12T15:32:00-04:00</updated>

		<published>2005-08-12T15:32:00-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=54128#p54128</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=54128#p54128"/>
		<title type="html"><![CDATA[Tcl performance, script optimization]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=54128#p54128"><![CDATA[
yet more performance hints:<br><br>put everything in a proc, inline Tcl code doesn't get that much optimized like byte-compiled proc does:<div class="codebox"><p>Code: </p><pre><code>% time {for {set i 0} {$i&lt;10000} {incr i} {lappend a $i}} 10035300 microseconds per iteration% proc init_me {} {          global b          for {set i 0} {$i&lt;10000} {incr i} {lappend b $i}      }% time {init_me} 10021888 microseconds per iteration</code></pre></div>don't use inline regexps too much:<div class="codebox"><p>Code: </p><pre><code>regexp "\[ \t\n\r\]" $str</code></pre></div>instead, save it into variable first and then use that variable:<div class="codebox"><p>Code: </p><pre><code>set ws "\[ \t\n\r\]"...regexp $ws $str</code></pre></div>the second form allows storing the compiled regexp in the Tcl_Obj representation of <em class="text-italics">$ws</em> and simply executing it on demand, whereas the first form could lead to compiling that regexp again and again (after interpreter's regexp cache has been exhausted)<br><br>don't use [catch] too often, it's slow and should be used only when you are pretty certain that it triggers very rarely; for example, this lazy line of code is 10 times slower than the [info exists] construct that follows it (provided <em class="text-italics">$a</em> doesn't exist):<div class="codebox"><p>Code: </p><pre><code>catch {set b $a}</code></pre></div><div class="codebox"><p>Code: </p><pre><code>if {[info exists a]} {set b $a}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5056">demond</a> — Fri Aug 12, 2005 3:32 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[demond]]></name></author>
		<updated>2005-08-12T14:38:20-04:00</updated>

		<published>2005-08-12T14:38:20-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=54124#p54124</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=54124#p54124"/>
		<title type="html"><![CDATA[Tcl performance, script optimization]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=54124#p54124"><![CDATA[
not only [expr] arguments, but all expressions in Tcl should be enclosed in braces; I've the bad habit to write:<div class="codebox"><p>Code: </p><pre><code>if [command $x $y $z] {   # stuff}</code></pre></div>don't do that; use:<div class="codebox"><p>Code: </p><pre><code>if {[command $x $y $z]} {   # stuff}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5056">demond</a> — Fri Aug 12, 2005 2:38 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[sKy]]></name></author>
		<updated>2005-08-10T12:51:31-04:00</updated>

		<published>2005-08-10T12:51:31-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=54002#p54002</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=54002#p54002"/>
		<title type="html"><![CDATA[Tcl performance, script optimization]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=54002#p54002"><![CDATA[
regular<div class="codebox"><p>Code: </p><pre><code>set result [expr 1000 + 1000]</code></pre></div><div class="codebox"><p>Code: </p><pre><code>set result [expr {1000 + 1000}]set result [expr { 1000 + 1000 * 1000 } ]</code></pre></div>This will be a little big faster.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=6101">sKy</a> — Wed Aug 10, 2005 12:51 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[demond]]></name></author>
		<updated>2005-08-10T04:09:31-04:00</updated>

		<published>2005-08-10T04:09:31-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=53983#p53983</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=53983#p53983"/>
		<title type="html"><![CDATA[Tcl performance, script optimization]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=53983#p53983"><![CDATA[
more performance tips:<br><br>Data types in Tcl 8.0 and greater are represented in Tcl_Obj internal object type; don't change the type of that representation if you can, for example use:<div class="codebox"><p>Code: </p><pre><code>if {[llength $alist] == 0}</code></pre></div>and not:<div class="codebox"><p>Code: </p><pre><code>if {[string compare {} $alist] == 0}</code></pre></div>(in the latter expression the internal representation of the argument list <em class="text-italics">$alist</em> is changed to string, which hurts the performance)<br><br>this might not be much relevant to eggdrop's bind triggers (which normally wouldn't be a performance bottleneck), but still:<div class="codebox"><p>Code: </p><pre><code>foreach {foo bar moo} [split $args] {break}</code></pre></div>is faster and more compact than:<div class="codebox"><p>Code: </p><pre><code>set foo [lindex [split $args] 0]set bar [lindex [split $args] 1]set moo [lindex [split $args] 2]</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5056">demond</a> — Wed Aug 10, 2005 4:09 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[demond]]></name></author>
		<updated>2005-07-29T23:16:24-04:00</updated>

		<published>2005-07-29T23:16:24-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=53506#p53506</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=53506#p53506"/>
		<title type="html"><![CDATA[Tcl performance, script optimization]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=53506#p53506"><![CDATA[
a fast in-place list update (courtesy of <a href="http://wiki.tcl.tk/73" class="postlink">DKF</a>):<div class="codebox"><p>Code: </p><pre><code>proc K {x y} {set x}set theList [lreplace [K $theList [set theList {}]] 7 42]</code></pre></div>what happens here? when you use [lreplace] the usual way, entire list gets duplicated (not elements though), manipulated and then copied back to the list variable, then the duplicate is destroyed<br><br>when you use the above method with so-called <strong class="text-strong">K combinator</strong> (an important notion in functional programming), list manipulation is done in-place, meaning duplication is eliminated (the K combinator in this case is functioning as get-and-unset proc)<br><br>on my machine, it's almost 50 times faster! operating on a big list of course:<div class="codebox"><p>Code: </p><pre><code>[demond@whitepine demond]$ tclsh8.4% proc K {a b} {set a}% for {set i 0} {$i&lt;100000} {incr i} {   lappend a $i; lappend b $i}% time {set a [lreplace $a 40 80]}24879 microseconds per iteration% time {set b [lreplace [K $b [set b {}]] 40 80]}537 microseconds per iteration</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=5056">demond</a> — Fri Jul 29, 2005 11:16 pm</p><hr />
]]></content>
	</entry>
	</feed>
