|
Lee Ludd
Scripted doors & windows
Join date: 16 May 2005
Posts: 243
|
03-24-2006 10:01
Does anybody know which is faster, llSubStringIndex or llListFindList, for determining whether a particular name is one of a set of (say) about 100 names. I don't care about issues realted to maintaining the list, or memory constraints. Just the speed of a lookup.
|
|
Kalleb Underthorn
Registered User
Join date: 30 Jul 2003
Posts: 40
|
03-24-2006 11:50
I was going to guess strings... but I wanted to make sure. default { state_entry() { list namesL; string namesS; string name64; integer i; llOwnerSay( "Spawning name list..."); for( i = 0; i < 100; i++ ) { name64 = llIntegerToBase64( i ); namesL += [name64]; namesS += name64+","; // llOwnerSay( (string)i ); } llOwnerSay( "Names list spawned... benchmarking"); float t = llGetTime(); for( i = 0; i < 100; i++ ) { llListFindList( namesL, [name64] ); } llOwnerSay( (string)(llGetTime()-t) + " seconds to find the last name 100 times (list)" ); t = llGetTime(); for( i = 0; i < 100; i++ ) { llSubStringIndex( namesS, name64 ); } llOwnerSay( (string)(llGetTime()-t) + " seconds to find the last name 100 times (string)" ); } }
Results From: someone Object: Names list spawned... benchmarking Object: 1.157347 seconds to find the last name 100 times (list) Object: 0.823427 seconds to find the last name 100 times (string)
EDIT: I would like to point out the data in these lists are relatively short, if the names length grows, the search time might push closer to equal. Strings are generally more efficient in memory and speed.
|
|
Lee Ludd
Scripted doors & windows
Join date: 16 May 2005
Posts: 243
|
03-24-2006 12:08
Thanks. Thanks especially for actually backing up your guess with an experiment.
For an operation that might be called once every 10 seconds or so, at the most, and even then, only for over the course of a few minutes, it doesn't look like it will make very much difference which approach I use. But using a list seems like overkill, so it's nice to know the string approach is marginally faster.
|