Firstly, $sockerr is irrelevant to the one line script. If there is a $sockerr, /sockread will read nothing and therefore will write nothing-- the socket will then subsequently close. It's not necessary to check this.
Secondly, "faster" is relative. Practically speaking, and given that packets are a few k each and xml/html files are on the order of a few k, this means a few extra triggers max; it shouldn't be noticeably slower.
I very much understand what the help file says. Of course rather than making
assumptions about what the help file
means, I prefer to test things myself:
alias testx { .remove test.txt | %xticks = $ticks | sockopen x yahoo.com 80 }
on *:SOCKOPEN:x:sockwrite -tn x GET / HTTP/1.0 | sockwrite -tn x Host: m.www.yahoo.com | sockwrite -tn x
on *:SOCKREAD:x:sockread &binvar | bwrite test.txt -1 -1 &binvar
on *:SOCKCLOSE:x:echo -a $calc($ticks - %xticks) ticks : $file(test.txt).size bytes
alias testy { .remove test.txt | %yticks = $ticks | sockopen y www.yahoo.com 80 }
on *:SOCKOPEN:y:sockwrite -tn y GET / HTTP/1.0 | sockwrite -tn y Host: m.www.yahoo.com | sockwrite -tn y
on *:SOCKREAD:y: {
if ($sockerr) halt
else {
var %br = 1
while (%br) {
sockread &binvar
bwrite test.txt -1 -1 &binvar
%br = $sockbr
}
}
}
on *:SOCKCLOSE:y:echo -a $calc($ticks - %yticks) ticks : $file(test.txt).size bytes
Using the 1 line method, the results are:
min: 109 ticks : 10031 bytes
max: 484 ticks : 10031 bytes
The average over 20 runs is 331.55 ticks
For the loop method you get:
min: 218 ticks : 10031 bytes
max: 343 ticks : 10031 bytes
The average over 20 runs is 268.35 ticks
So it's slightly faster, yes. Significantly? 20% might be considered significant if you were downloading 1000s of pages, however in that case, the benefit of a slower script would be extra responsiveness in mIRC, since while loops block the UI from updating. In normal cases it should be barely noticeable.
Note #1: the file downloaded is on the fat end compared to other HTML pages which are usually around 2-3k, not 10k. This is already the worst case scenario for the one line method. You would get less re-triggering and variance from smaller pages like google, which yields ~180 ticks vs ~140 ticks.
Also of note is that the variance for the one line method is much wider-- the best case scenario is actually twice as fast as the best case of the loop method... draw your own conclusion from that one.
In any case, for most situations, a one liner is quite sufficient in terms of performance. The loop method is certainly a
far cry from the
far faster the help file claims.