Nmap Development mailing list archives
Re: [NSE][PATCH] string_ext library
From: "Patrick Donnelly" <batrick.donnelly () gmail com>
Date: Thu, 2 Oct 2008 18:06:30 -0600
On Wed, Oct 1, 2008 at 4:43 AM, Sven Klemm <sven () c3d2 de> wrote:
Hmm extending string would really make more beautyful code IMO. Do you have any numbers regarding the performance difference? Does that imply that using ("abc"):foo() is also bad for performance since this probably also does a global string lookup instead of using a local copy of the string table.
I did a quick benchmark using os.clock (code attached): For string.upper, in a tight loop with 5e6 iterations, it ends up being about a 200ms linear difference between (worst to best): string.upper (global lookup + upper lookup), string.upper (local reference to string + upper lookup), upper (local reference to string.upper). The exact numbers in order are (in seconds): a = 1.85 b = 1.68 c = 1.4 The metamethod lookup ends up being about the same (as expected) as the global lookup + upper lookup (a): d = 1.78 After extending the string module and looking up tohex (which is just string.upper for consistency): a = 1.98 b = 1.78 c = 1.4 d = 1.91 As you can see, it's not a huge difference. I still would advocate the use of local references to functions as in a register based virtual machine it will always be optimal.
Currently there is already a tohex() function in stdnse.lua which only works for numbers. It's probably best to rename my function to tohex() since this is more in line with the lua function names. Do you think we should put this function into its own module or do you think it should be added to stdnse?
I would actually recommend extending the tohex() function to handle strings or numbers. Perhaps the other functions could be extended in the same way as well. Cheers, -- -Patrick Donnelly "One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say." -Will Durant
Attachment:
local_test.lua
Description:
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- Re: [NSE][PATCH] string_ext library Sven Klemm (Oct 01)
- Re: [NSE][PATCH] string_ext library Patrick Donnelly (Oct 02)
- Re: [NSE][PATCH] string_ext library Sven Klemm (Oct 03)
- Re: [NSE][PATCH] string_ext library Sven Klemm (Oct 03)
- Re: [NSE][PATCH] string_ext library David Fifield (Oct 03)
- Re: [NSE][PATCH] string_ext library Sven Klemm (Oct 03)
- Re: [NSE][PATCH] string_ext library Sven Klemm (Oct 03)
- Re: [NSE][PATCH] string_ext library Patrick Donnelly (Oct 02)