View Single Post
09-28-11, 11:55 AM   #12
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by Vladinator View Post
This is what I found, obviously the built in code handles it much faster.

The code I used: http://pastebin.com/Xfc2wgpF

...

Traversing used 0.6973 ms while using the table key used only 0.0016 ms. So with a lot of data it's more efficient to find using keys, rather than traversing and matching, really.
This is because the internal storage method for table keys uses a hash indexing, Lua doesn't need to transverse an array internally to find a value. Even if it did, the C code would run many times faster than running Lua code through its own scripting engine.

For future reference, I'd suggest using debugprofilestart() and debugprofilestop() to benchmark CPU time spent. debugprofilestop() returns the time from when debugprofilestart() was last called with much higher precision than comparing timestamps from GetTime(). This lack in precision is what's causing the 0 ms readings and happens a lot when trying to compare Lua C functions and internal Lua processing.

The limit on GetTime() precision is because it's merely a Lua wrapper for the C function gettickcount() from the system kernel that returns an integer describing system uptime in milliseconds. GetTime() simply returns this integer divided by 1000.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote