ok, update. and this is now weird.
I have made it so each test is as close to the same as possible, with the only variance being the method of lookup. each is called from a function to make sure the function call wasnt adding extra baggage to the process. I also tested all 3 padding methods i could think of.
I even made the query only request the number 1, so that row length doesnt even figure in.
so here are the results. Averages of 5 runs with 50 lookup each.
average seconds pct faster then next up
split octets: 28 30%
string: 36.4 4%
numeric: 38 26%
padded Caseloop: 48 1%
padded ifloop: 48.4 7%
padded right: 51.8 0%
Split 4 column octets works the fastest it seems.
but frankly im baffled. 2.4 million records, no indexing, and string based lookup is faster than numeric?!?!@??
functions for reference
function ipsplit(ip)
dim a,sql
a=split(ip,".")
sql="select top 1 '1' from ips where ip1="&a(0)&" and ip2="&a(1)&" and ip3="&a(2)&" and ip4="&a(3)
ipsplit=sql
end function
function ipstring(ip)
dim sql
sql="select top 1 '1' from ips where ipstring='"&ip&"'"
ipstring=sql
end function
function ippaddedright(ip)
dim iparr,sql
iparr=split(ip,".")
sql="select top 1 '1' from ips where ippadded="&Right("00" & iparr(0),3)&Right("00" & iparr(0),3)&Right("00" & iparr(0),3)&Right("00" & iparr(0),3)
ippaddedright=sql
end function
function ippaddedcase(ip)
dim iparr,sql,octet,pad
iparr=split(ip,".")
pad=""
for each octet in iparr
select case len(octet)
case 1 pad=pad&"00"&octet
case 2 pad=pad&"0"&octet
case 3 pad=pad&octet
end select
next
sql="select top 1 '1' from ips where ippadded="&pad
ippaddedcase=sql
end function
function ippaddedif(ip)
dim iparr,sql,octet,pad
iparr=split(ip,".")
pad=""
for each octet in iparr
if len(octet)=1 then
pad=pad&"00"&octet
elseif len(octet)=2 then
pad=pad&"0"&octet
else
pad=pad&octet
end if
next
sql="select top 1 '1' from ips where ippadded="&pad
ippaddedif=sql
end function
function IP2Num(ip)
dim str1,str2,str3,str4,sip,sql
sip=ip
str1=left(sip,instr(sip,".")-1)
sip=mid(sip,instr(sip,".")+1)
str2=left(sip,instr(sip,".")-1)
sip=mid(sip,instr(sip,".")+1)
str3=left(sip,instr(sip,".")-1)
str4=mid(sip,instr(sip,".")+1)
sql = "select top 1 '1' from ips where ipnum="&str1*256*256*256+str2*256*256+str3*256+str4
ip2num=sql
end function