How many users are in the channel?

Keeping data in an unordered text file is terrible for performance. Think about it. If you have 2 users, that's 3 searches/comparisons. 1 to find the first, 2 to find the second. Expand that to 100 users and it's 5,050 comparisons. Expand that to 1000 users and it's 500,500 comparisons. This is n^2 time on disk.

Using a modified version of your script I checked 100, 1000, and 2000 users and the times were 1 second, 24 seconds, and 1 minute 16 seconds respectively. This was on my ssd, I expect an hdd would be somewhat slower.

Storing the values in an ini file, loading them to a hash table, and then saving to the ini file would be much faster. With a hash table, you don't search at all. With 1000 users you get 1000 hashes, 1000 increments, and 1 file save. This is n time in memory.

Testing this out quickly, I was able to increase the values of 100,000 users in 8-12 seconds. Saving to a binary instead of an ini file I was able to do this in 5 seconds. Postponing the save for later I could update the table of 100,000 users in 3 seconds.

Code:
alias awardpoints {
  var %chan = $$1, %table = coins. $+ %chan, %file = coins.ini

  if (!$hget(%table)) {
    hmake %table
    if $ini(%file,%chan) hload -i %table %file %chan
  }

  var %i = 1, %n = $nick(%chan,0)
  while (%i <= %n) {
    hinc %table $nick(%chan,%i)
    inc %i
  }

  hdel %table nightbot
  hdel %table tylerb0t
  hdel %table tylersgaming

  hsave -i %table %file %chan
}


Ways to possibly improve on this further: Do not load the entire ini file into the table, instead only add users currently in the channel and append this table to the ini file with the -a switch. Do not save the file immediatley, save it on a timer in order to allow mIRC to process more IRC events. Play with the size of the hash table.

*For testing purposes I used a simple integer for the user name, I don't know what performance impact using $nick will have.

Quote:
its a crash and I don't know, my irc just says not responding and shuts down.

If you're told it's not responding and given the option to wait or close, that's freezing.

Last edited by Loki12583; 20/08/14 07:59 PM.