mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2007
Posts: 66
B
beer Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Jul 2007
Posts: 66
Hi,

From what I gather, for the sake of speed it's good practice to limit the number of $hget's you do to a minimum. If I have a hash with say 10 sub-values, but I'd only access 2-3 at a time, would it be better keep them all separate as their own hash table entries, or would it be faster to store all of them in a single hash entry using a field separator and then $gettok'ing out the fields I need? The entire amount of data for each entry+sub-entries would be about 500 characters or less with probably no more than 250 total different datasets. 11 table entries per dataset * 250 datasets = 2750 total table entries. 250 total datasets * 500 characters = 125,000 characters for a full table.

So for example, the hash table might look like:
Code
item1: item description
item1.data1: some value
item1.data2: some value
item1.data3: some value
...
item1.data10: some value

var %data3 = $hget(table,item1.data3), %data5 = $hget(table,item1.data5), %data10 = $hget(table,item1.data10)


vs.
Code
item1: description|value1|value2|value3|...|value10

var %temp = $hget(table,item1)
var %field3 = $gettok(%temp,3,124), %field5 = $gettok(%temp,5,124), %field10 = $gettok(%temp,10,124)


I'm guessing it would be faster to do the single $hget into the %temp var and then multiple $gettok's through the 500 characters rather than multiple $hget's through up to 125,000 characters. But that's only a guess and then is speed much of a factor at this table/data size?

Thanks!

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
$hget() is not slow, it's fast, it's what makes hash table great.

Depending on what you're doing, using the item name to store two different value (item1.data1) makes sure you're ok with performances, editing each value is a /hadd call with two dynamic values to form the item name, and usually getting these two values is not considered much overhead. Accessing is also a single $hget call with the two values.
If you're using one item to store multiple value separated by tokens (which i find more handy myself), if you need to edit one of the value, you end up with a lot of overhead because you also have to gather the others tokens.
However using tokens allows you to use $*, with tokenize, which is faster than a while.

So, for example, if you don't plan to edit the data too much/too often, and end up reading the data most of the time, tokens + tokenize + $* may be a good idea for best performances.
If you end up having too many item name with the same prefix, you can also put them in their own hash table.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard