Consider the following aliases save1, save2, and testdata:
alias save1 {
var %t = $ticks
hsave -i test test.txt
echo -a Time taken save1: $calc($ticks - %t) ms
}
[color:red] [/color]
alias save2 {
var %t = $ticks
if $fopen(test) { .fclose test }
.fopen -o test test.txt
if $ferr {
echo -a Error opening test.txt
return
}
var %a = 1
while $hget(test,%a).item {
.fwrite -n test $+($v1,=,$hget(test,$v1))
inc %a
}
.fclose test
echo -a Time taken save2: $calc($ticks - %t) ms
}
[color:red] [/color]
alias testdata {
hmake test
var %a = 1000, %b = $str(lol,20)
while %a {
hadd test %a %b
dec %a
}
}
Make sure there is no test.txt in your main mIRC folder.
Results with 1000 hashtable items and 20x lol as data:
-----------------------------------------------------------------
save1 : 328 ms
save2: 63 ms
Results with 5000 hashtable items and 20x lol as data:
-----------------------------------------------------------------
save1: 8313 ms
save2: 2797 ms
Results with 1000 hashtable items and item number as data:
-----------------------------------------------------------------------
There is considerably less data now.
save1: 125 ms
save2: 63 ms
In other words, the smaller the data, the faster -i works.
[*] Isn't it somewhat weird, that an internal command like /hsave -i <table> <file> works considerably slower than a scripted example like /save2 ?
[*] If it really is faster, does that mean that the /hsave -i command could be coded more efficiently internally?
[*] Btw the -o (overwrite) seems bugged in /hsave -oi, because if I do /save2, ensure that the file is closed, and then do /save1, the first alias will append the data to test.txt, instead of overwriting it. So make sure to delete test.txt each time you try the /save1 alias after using /save2.
Btw the reason I prefer using /save2 in the first place, was not because of the speed increase, but because it will not corrupt nicknames which contain [ and/or ].
The hash table serves as a means to store user data (Role playing game). In other words, there is a lot of data for each user (they each have around 20 characteristics), which means the speed increase is drastic.
Then again, I only had 1.5 hours of sleep today (damn roof workers), so disregard this, if none of it makes sense.
Greets