mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2004
Posts: 2,019
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Consider the following aliases save1, save2, and testdata:

Code:
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


Gone.
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
mIRC's INI writing is slower because it has true INI support, whereas yours just writes to a text file in a given format - it's not real INI support and the format doesn't even include an INI section header (which is almost certainly the cause of your /hsave -io problems - not a bug).

Try writing your alias to support checking the entire file for an existing section; then for each item it writes checking if that item already exists and if so overwriting it, otherwise appending it to the end of that section in place. Then compare speeds, I think your results will have changed drastically.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Well,

you were right about the -o thing not working properly, because there was no topic. I do think that is a bit odd, since what should it matter what structure the file is in right now, before saving, if it's going to be overwritten entirely anyway? Though, it's reasonable I suppose.

I went ahead and modified the alias, to make it write a section, which was basically just add a line ".fwrite -n test [hashtable]". Now it resembled the exact same as if you would /hsave -i the hash table to a brand new textfile (note I'm saying new file)

After that I loaded the text file with /hload -i test test.txt. I performed some commands like $readini, and /writeini on the file, and everything worked fine.

The benchmarks returned the exact same results, that is 63 ms for /save2 and 328 ms for /save1.

Now, I understand what you are saying. The reason the /hsave -i is slower, in this particular case, because it has to check for existing topics, etc., take into account the format and structure of INI files. That would make sense, that it would be slower than using a loop and fwrite, since my alias doesn't have to check the structure, it simply overwrites the file without looking back (which I first thought /hsave -oi would also do, cuz of the o flag)

I can conclude (I think), that for my purpose, which is temp storing player data with the intention to use /filter on it to return top statistics, my alias will be best suited.

If I were to have to write to a file, which has several topics, and cannot be overwritten as a whole, then the /hsave -i solution would then be fastest, as the difference is that it supports true INI support, where my alias doesn't (limited to having 1 topic in a file, and only overwriting).

Well, thanks for the info, it makes sense.

Greets

Last edited by FiberOPtics; 11/11/04 09:05 PM.

Link Copied to Clipboard