Quote:

I haven't got the time/inclination to create and run benchmarks at the moment, why not run the benchmarks yourself? If you do, post the benchmark code you use aswell.


The idea was I was hoping someone else had already done the bench, since I, like you, am pretty lazy cool

Anyway, modifying the code above (Thanks Stranger), I ended up with these results, running the test on 6 arrays with sizes ranging from 100-600 elements. I used 100-600 because, according to my hypothesis, variable arrays should start becoming slower after 300 elements. I ran the test three times for good measure.

Note that while all times are calculated to be in seconds, using $ticks is an approximate calculation of a true second. For simplicity, however, i'll just call them seconds from here on in.

Results:
Code:
Test results for hadd,setv,file tests:
 
size:  100 	200 	300 	400 	500 	600
-----------------------------------------------------
hadd:  0	0	0	0.015	0.016	0.031
setv:  0	0.016	0	0.016	0.031	0.031
file:  0.047	0.078	0.125	0.156	0.188	0.25
 
Test results for hadd,setv,file tests:
 
size:  100 	200 	300 	400 	500 	600
-----------------------------------------------------
hadd:  0	0	0.015	0.016	0.015   0.031
setv:  0	0.015	0.016	0.031   0.032   0.032
file:  0.047	0.063	0.109	0.141   0.187   0.234
 
Test results for hadd,setv,file tests:
 
size:  100 	200 	300 	400 	500 	600
-----------------------------------------------------
hadd:  0        0       0       0.015   0.016   0.015
setv:  0        0.016   0.016   0.016   0.031   0.047
file:  0.046	0.078   0.125   0.156   0.188   0.219


Discussion:
First off lets conclude that file handling is largely slower, this was not under debate but I left it there as a 'control', i suppose.

Interestingly though, in an iterative array, this test shows that /set only seems to be slower on arrays of size 200 and 500 and sometimes 400. I ran extra tests using the code (following this report) and realized that the slowdown on /set seems to be more or less 'random'.

Keep in mind though, that according to my hypothesis, /set should start slowing down at or around 300, and this seems to be exactly the case. Before 300, the difference is 'unmeasurable'.

However, even after 300, the difference between var and hadd seems to max out at around 0.03 seconds, or 3 milliseconds, for the array sizes used. This is a truly small number, and I think it's safe to say that 3 milliseconds will not create any noticeable time difference in any script process.

Conclusion:
Let me just say first off, that I was never debating variable arrays being faster than hash tables for arrays of many elements (1000 or greater). I'll leave the tests up to you, but the results I saw with the test code (given below) show that hash tables are truly better for any array greater than 1000 elements.

However, my original assumption was that variables and hash tables are more or less equivalent in 'efficiency' and 'speed' for arrays of size under and around 300. Test results proved that this is the case, even up to 600 elements.

Therefore, I think it's fair to say that hash tables are not always necessary for a scripter to use when dealing with arrays, at least for reasonable purposes (clone scanners, nick completion, flood detection, anything dealing with nicknames). I think I can maintain this argument with the results shown above.

Code:

I didn't change the vital organs of the code given by Stranger, I just updated the way it reports the results to make it cleaner. I also made a /bench function which tests each array incrementing by 100 from $$1 to $$2. Finally, a minor adjustment: I changed the names because there is a name conflict for $hash and $file

Code:
alias _hash {
  hmake test 10
  var %x = 0
  var %ms = $ticks  
  while (%x < $$1) {
    hadd test %x 0
    inc %x 1
  }
  %x = $calc(($ticks - %ms) / 1000)
  hfree test
  return %x
}

alias _var {
  var %x = 0
  var %ms = $ticks
  while (%x < $$1) {
    set %test_ $+ %x 0
    inc %x 1
  }
  %x = $calc(($ticks - %ms) / 1000) 
  unset %test_*
  return %x
}

alias _file {
  var %x = 0
  var %ms = $ticks 
  while (%x < $$1) {
    write test.txt 0
    inc %x
  }
  %x = $calc(($ticks - %ms) / 1000) 
  write -c test.txt
  return %x
}

; usage: /bench <START> <END>
alias bench {
  var %h, %v, %f, %s, %i = $$1
  while (%i <= $$2) {
    %s = %s %i $+ $chr(9)
    %h = %h $_hash(%i) $+ $chr(9)
    %v = %v $_var(%i) $+ $chr(9)
    %f = %f $_file(%i) $+ $chr(9)
    inc %i 100
  }
  window -a -t4 @Test-results
  aline -p @Test-results Test results for hadd,setv,file tests:
  aline -p @Test-results $chr(3)
  aline -p @Test-results size: $chr(3) %s
  aline -p @Test-results -----------------------------------------------------
  aline -p @Test-results hadd: $chr(3) %h 
  aline -p @Test-results setv: $chr(3) %v
  aline -p @Test-results file: $chr(3) %f
  aline -p @Test-results $chr(3)
}


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"