소스 검색

添加一些测试示例

kangsongzhang 6 년 전
부모
커밋
19516b1197

+ 26 - 0
call与pcall调用对比/t.lua

@@ -0,0 +1,26 @@
+local slen = string.len
+local function func(a, b)
+	local x = a + b
+	return x
+end
+
+
+local t = os.clock()
+for i = 1, 1000000 do
+	func(1, 2)
+end
+print("call: ", os.clock() - t)
+
+
+t = os.clock()
+for i = 1, 1000000 do
+	pcall(func, 1, 2)
+end
+print("pcall: " ,os.clock() - t)
+
+local a[id] = {} 
+
+for k, v in pairs(a) 
+
+end
+os.execute("PAUSE")

+ 29 - 0
函数返回成员和直接访问效率对比/t.lua

@@ -0,0 +1,29 @@
+
+local tab = 
+{
+	x = 3
+}
+function tab:getx()
+	return self.x
+end
+
+local t = os.clock()
+for i = 1, 10000000 do
+	local y = tab.x
+end
+print(os.clock() - t)
+
+t = os.clock()
+for i = 1, 10000000 do
+	local y = tab:getx()
+end
+print(os.clock() - t)
+
+
+os.execute("PAUSE")
+
+--[[
+测试结果为函数封装访问是直接调用的3倍消耗,
+但是为了实现类的封装大部分地方还是建议尽量采用封装调用,
+可以适当的对调用极其频繁而且逻辑非常简易的地方做这个优化。
+]]

+ 135 - 0
字符串分割函数的几种写法效率对比/main.lua

@@ -0,0 +1,135 @@
+local string = string
+local sfind = string.find
+local slen = string.len
+local ssub = string.sub
+local sgub = string.gsub
+local sformat = string.format
+local setmetatable = setmetatable
+local tinsert = table.insert
+
+string.split1 = function (szFullString, szSeparator)
+	local nFindStartIndex = 1
+	local nSplitIndex = 1
+	local nSplitArray = {}
+	while true do
+	   local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
+	   if not nFindLastIndex then
+			nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
+			break
+	   end
+	   nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
+	   nFindStartIndex = nFindLastIndex + string.len(szSeparator)
+	   nSplitIndex = nSplitIndex + 1
+	end
+	return nSplitArray
+end
+
+
+function string.split2(szFullString, szSeparator)
+	local nFindStartIndex = 1
+	local nSplitIndex = 1
+	local nSplitArray = {}
+	while true do
+	   local nFindLastIndex = sfind(szFullString, szSeparator, nFindStartIndex)
+	   if not nFindLastIndex then
+			nSplitArray[nSplitIndex] = ssub(szFullString, nFindStartIndex,  slen(szFullString))
+			break
+	   end
+	   nSplitArray[nSplitIndex] = ssub(szFullString, nFindStartIndex, nFindLastIndex - 1)
+	   nFindStartIndex = nFindLastIndex + 1
+	   nSplitIndex = nSplitIndex + 1
+	end
+	return nSplitArray
+end
+
+function string.split3(str, sep)
+  local parts = {__index = tinsert}
+  setmetatable(parts, parts)
+  sgub(str, sformat("([^%s]+)", sep), parts)
+  setmetatable(parts, nil)
+  parts.__index = nil
+  return parts
+end
+
+function string.split4(str, sep)
+	local ary = {}
+	sgub(str, sformat("([^%s]+)", sep), function(c) ary[#ary+1] = c end)
+	return ary
+end
+
+function string.split6(str, mark)
+	mark = mark or ",";
+	local setStr = {};
+	local marklen = string.len(mark);
+	local slength = string.len(str);
+	local index = 0
+	local start = 1
+	while true do
+	    index = string.find(str, mark, start)   -- find 'next' 返回 i 和 j 
+	    if index == nil then break end
+		local s = string.sub(str, start, index-1)
+	    table.insert(setStr, s)
+		start = index + marklen;
+	end
+	if start <= slength then
+		local s = string.sub(str, start, slength)
+	    table.insert(setStr, s)
+	end
+	return setStr;
+end
+
+
+local s_ary = {}
+local s_i = 1
+local function func(c)
+	s_ary[s_i] = c
+	s_i = s_i + 1
+end
+function string.split5(str, sep)
+	s_ary = {}
+	s_i = 1
+	sgub(str, sformat("([^%s]+)", sep), func)
+	return s_ary
+end
+
+
+
+local s = "1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20"
+
+local t = os.clock()
+for i = 1, 100000 do
+	local x = string.split1(s, "+")
+end
+print("string.split: " ,os.clock() - t)
+
+t = os.clock()
+for i = 1, 100000 do
+	local x = string.split2(s, "+")
+end
+print("string.split2: " , os.clock() - t)
+
+t = os.clock()
+for i = 1, 100000 do
+	local x = string.split3(s, "+")
+end
+print("string.split3: " , os.clock() - t)
+
+t = os.clock()
+for i = 1, 100000 do
+	local x = string.split4(s, "+")
+end
+print("string.split4: " , os.clock() - t)
+
+t = os.clock()
+for i = 1, 100000 do
+	local x = string.split5(s, "+")
+end
+print("string.split5: " , os.clock() - t)
+
+t = os.clock()
+for i = 1, 100000 do
+	local x = string.split6(s, "+")
+end
+print("string.split6: " , os.clock() - t)
+
+os.execute("PAUSE")

+ 32 - 0
字符串连接效率/t.lua

@@ -0,0 +1,32 @@
+--------------------------------------
+-- ..
+local text
+local t = os.clock()
+text = ""
+for i = 1, 10000 do
+	text = text .. tostring(i)
+end
+print("[1] time: " ,os.clock() - t)
+
+--------------------------------------
+-- format
+local string_format = string.format
+t = os.clock()
+text = ""
+for i = 1, 10000 do
+	text = string_format("%s%s", text, tostring(i))
+end
+print("[2] time: " ,os.clock() - t)
+
+--------------------------------------
+-- concat
+local list = {}
+local table_insert = table.insert
+t = os.clock()
+text = ""
+for i = 1, 10000 do
+	table_insert(list, tostring(i))
+end
+text = table.concat(list, '')
+print("[3] time: " ,os.clock() - t)
+os.execute("PAUSE")

+ 31 - 0
定义域对效率影响对比/t.lua

@@ -0,0 +1,31 @@
+local function func1()
+	for i = 1, 1000000 do
+		local x = 1
+		if i % 2 == 0 then
+			x = 2
+		end
+	end
+end
+
+local function func2()
+	local x = 1
+	for i = 1, 1000000 do
+		if i % 2 == 0 then
+			x = 2
+		end
+	end
+end
+
+local t = os.clock()
+func1()
+print("1: " ,os.clock() - t)
+
+
+t = os.clock()
+func2()
+print("2: " ,os.clock() - t)
+
+os.execute("PAUSE")
+
+-- 结果
+-- 基本无差异

+ 47 - 0
数组插入数据方法效率对比/t.lua

@@ -0,0 +1,47 @@
+local list1, list2, list3, list4 = {}, {}, {}, {}
+local count4 = 0
+local table_insert = table.insert
+
+function func1()
+	table_insert(list1, 1)
+end
+
+function func2()
+	table.insert(list2, 1) -- 顺便再关注一下local的效率差异
+end
+
+function func3()
+	list3[#list3 + 1] = 1
+end
+
+function func4()
+	count4 = count4 + 1
+	list2[count4] = 1
+end
+
+local t = os.clock()
+for i = 1, 10000000 do
+	func1()
+end
+print("func1: " ,os.clock() - t)
+
+t = os.clock()
+for i = 1, 10000000 do
+	func2()
+end
+print("func2: " ,os.clock() - t)
+
+t = os.clock()
+for i = 1, 10000000 do
+	func3()
+end
+print("func3: " ,os.clock() - t)
+
+t = os.clock()
+for i = 1, 10000000 do
+	func4()
+end
+print("func4: " ,os.clock() - t)
+
+
+os.execute("PAUSE")

+ 19 - 0
本地函数与全局函数访问效率对比/t.lua

@@ -0,0 +1,19 @@
+
+local x = 1.01
+
+local t = os.clock()
+for i = 1, 1000000 do
+	local y = math.ceil(x)
+end
+
+print(os.clock() - t)
+local math_ceil = math.ceil
+
+--local type1 = type
+t = os.clock()
+for i = 1, 1000000 do
+	local y = math_ceil(x)
+end
+print(os.clock() - t)
+
+os.execute("PAUSE")

+ 203 - 0
注释例子/Docs/files/test.html

@@ -0,0 +1,203 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+    <title>Reference</title>
+    <link rel="stylesheet" href="../luadoc.css" type="text/css" />
+	<!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
+</head>
+
+<body>
+<div id="container">
+
+<div id="product">
+	<div id="product_logo"></div>
+	<div id="product_name"><big><b></b></big></div>
+	<div id="product_description"></div>
+</div> <!-- id="product" -->
+
+<div id="main">
+
+<div id="navigation">
+
+
+<h1>LuaDoc</h1>
+<ul>
+	
+	<li><a href="../index.html">Index</a></li>
+	
+</ul>
+
+
+<!-- Module list -->
+
+
+
+<!-- File list -->
+
+<h1>Files</h1>
+<ul>
+
+	<li><strong>test.lua</strong></li>
+	
+</ul>
+
+
+
+
+
+
+</div> <!-- id="navigation" -->
+
+<div id="content">
+
+<h1>File <code>test.lua</code></h1>
+
+
+
+
+
+
+
+<h2>Functions</h2>
+<table class="function_list">
+
+	<tr>
+	<td class="name" nowrap><a href="#CTestClass:func">CTestClass:func</a>&nbsp;(p1)</td>
+	<td class="summary">成员函数 </td>
+	</tr>
+
+	<tr>
+	<td class="name" nowrap><a href="#CTestClass:new">CTestClass:new</a>&nbsp;(id)</td>
+	<td class="summary">创建对象 </td>
+	</tr>
+
+</table>
+
+
+
+
+<h2>Tables</h2>
+<table class="table_list">
+
+	<tr>
+	<td class="name" nowrap><a href="#CTestClass">CTestClass</a></td>
+	<td class="summary">这是一个测试类 </td>
+	</tr>
+
+</table>
+
+
+
+<br/>
+<br/>
+
+
+
+
+<h2><a name="functions"></a>Functions</h2>
+<dl class="function">
+
+
+
+<dt><a name="CTestClass:func"></a><strong>CTestClass:func</strong>&nbsp;(p1)</dt>
+<dd>
+成员函数
+
+
+<h3>Parameters:</h3>
+<ul>
+	
+	<li>
+	  <code><em>p1</em></code>: 参数1说明
+	</li>
+	
+</ul>
+
+
+
+
+
+
+
+
+<h3>See also:</h3>
+<ul>
+	
+	<!-- <li><a href="#../files/test.html#CTestClass:funcCTestClass:func"> -->
+	<li><a href="#CTestClass:func">
+		CTestClass:func</li>
+	</a>
+	
+</ul>
+
+</dd>
+
+
+
+
+<dt><a name="CTestClass:new"></a><strong>CTestClass:new</strong>&nbsp;(id)</dt>
+<dd>
+创建对象
+
+
+<h3>Parameters:</h3>
+<ul>
+	
+	<li>
+	  <code><em>id</em></code>: 根据id创建类
+	</li>
+	
+</ul>
+
+
+
+
+
+
+
+
+</dd>
+
+
+</dl>
+
+
+
+
+<h2><a name="tables"></a>Tables</h2>
+<dl class="table">
+
+<dt><a name="CTestClass"></a><strong>CTestClass</strong></dt>
+<dd>这是一个测试类<br /><br />
+
+
+<h3>Fields:</h3>
+<ul>
+	
+	<li>
+	  <code><em>name</em></code>: 这里的重要的成员参数说明
+	</li>
+	
+</ul>
+
+
+</dd>
+
+
+</dl>
+
+
+
+
+</div> <!-- id="content" -->
+
+</div> <!-- id="main" -->
+
+<div id="about">
+	<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
+</div> <!-- id="about" -->
+
+</div> <!-- id="container" -->	
+</body>
+</html>

+ 84 - 0
注释例子/Docs/index.html

@@ -0,0 +1,84 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+    <title>Reference</title>
+    <link rel="stylesheet" href="luadoc.css" type="text/css" />
+	<!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
+</head>
+
+<body>
+<div id="container">
+
+<div id="product">
+	<div id="product_logo"></div>
+	<div id="product_name"><big><b></b></big></div>
+	<div id="product_description"></div>
+</div> <!-- id="product" -->
+
+<div id="main">
+
+<div id="navigation">
+
+
+<h1>LuaDoc</h1>
+<ul>
+	
+	<li><strong>Index</strong></li>
+	
+</ul>
+
+
+<!-- Module list -->
+
+
+
+<!-- File list -->
+
+<h1>Files</h1>
+<ul>
+
+	<li>
+		<a href="files/test.html">test.lua</a>
+	</li>
+
+</ul>
+
+
+
+
+
+
+</div> <!-- id="navigation" -->
+
+<div id="content">
+
+
+
+
+
+
+
+<h2>Files</h2>
+<table class="file_list">
+<!--<tr><td colspan="2">Files</td></tr>-->
+
+	<tr>
+		<td class="name"><a href="files/test.html">test.lua</a></td>
+		<td class="summary"></td>
+	</tr>
+
+</table>
+
+
+</div> <!-- id="content" -->
+
+</div> <!-- id="main" -->
+
+<div id="about">
+	<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
+</div> <!-- id="about" -->
+
+</div> <!-- id="container" -->	
+</body>
+</html>

+ 286 - 0
注释例子/Docs/luadoc.css

@@ -0,0 +1,286 @@
+body { 
+    margin-left: 1em; 
+    margin-right: 1em; 
+    font-family: arial, helvetica, geneva, sans-serif;
+	background-color:#ffffff; margin:0px;
+}
+
+code {
+    font-family: "Andale Mono", monospace; 
+}
+
+tt {
+    font-family: "Andale Mono", monospace; 
+}
+
+body, td, th { font-size: 11pt; }
+
+h1, h2, h3, h4 { margin-left: 0em; }
+
+textarea, pre, tt { font-size:10pt; }
+body, td, th { color:#000000; }
+small { font-size:0.85em; }
+h1 { font-size:1.5em; }
+h2 { font-size:1.25em; }
+h3 { font-size:1.15em; }
+h4 { font-size:1.06em; }
+
+a:link { font-weight:bold; color: #004080; text-decoration: none; }
+a:visited { font-weight:bold; color: #006699; text-decoration: none; }
+a:link:hover { text-decoration:underline; }
+hr { color:#cccccc }
+img { border-width: 0px; }
+
+
+h3 { padding-top: 1em; }
+
+p { margin-left: 1em; }
+
+p.name { 
+    font-family: "Andale Mono", monospace; 
+    padding-top: 1em;
+    margin-left: 0em; 
+}
+
+blockquote { margin-left: 3em; }
+
+pre.example {
+    background-color: rgb(245, 245, 245);
+    border-top-width: 1px;
+    border-right-width: 1px;
+    border-bottom-width: 1px;
+    border-left-width: 1px;
+    border-top-style: solid;
+    border-right-style: solid;
+    border-bottom-style: solid;
+    border-left-style: solid;
+    border-top-color: silver;
+    border-right-color: silver;
+    border-bottom-color: silver;
+    border-left-color: silver;
+    padding: 1em;
+    margin-left: 1em;
+    margin-right: 1em;
+    font-family: "Andale Mono", monospace; 
+    font-size: smaller;
+}
+
+
+hr { 
+    margin-left: 0em;
+	background: #00007f; 
+	border: 0px;
+	height: 1px;
+}
+
+ul { list-style-type: disc; }
+
+table.index { border: 1px #00007f; }
+table.index td { text-align: left; vertical-align: top; }
+table.index ul { padding-top: 0em; margin-top: 0em; }
+
+table {
+    border: 1px solid black;
+	border-collapse: collapse;
+    margin-left: auto;
+    margin-right: auto;
+}
+th {
+    border: 1px solid black;
+    padding: 0.5em;
+}
+td {
+    border: 1px solid black;
+    padding: 0.5em;
+}
+div.header, div.footer { margin-left: 0em; }
+
+#container
+{
+	margin-left: 1em;
+	margin-right: 1em;
+	background-color: #f0f0f0;
+}
+
+#product
+{
+	text-align: center;
+	border-bottom: 1px solid #cccccc;
+	background-color: #ffffff;
+}
+
+#product big {
+	font-size: 2em;
+}
+
+#product_logo
+{
+}
+
+#product_name
+{
+}
+
+#product_description
+{
+}
+
+#main
+{
+	background-color: #f0f0f0;
+	border-left: 2px solid #cccccc;
+}
+
+#navigation
+{
+	float: left;
+	width: 18em;
+	margin: 0;
+	vertical-align: top;
+	background-color: #f0f0f0;
+	overflow:visible;
+}
+
+#navigation h1 {
+	background-color:#e7e7e7;
+	font-size:1.1em;
+	color:#000000;
+	text-align:left;
+	margin:0px;
+	padding:0.2em;
+	border-top:1px solid #dddddd;
+	border-bottom:1px solid #dddddd;
+}
+
+#navigation ul
+{
+	font-size:1em;
+	list-style-type: none;
+	padding: 0;
+	margin: 1px;
+}
+
+#navigation li
+{
+	text-indent: -1em;
+	margin: 0em 0em 0em 0.5em;
+	display: block;
+	padding: 3px 0px 0px 12px;
+}
+
+#navigation li li a
+{
+	padding: 0px 3px 0px -1em;
+}
+
+#content
+{
+	margin-left: 18em;
+	padding: 1em;
+	border-left: 2px solid #cccccc;
+	border-right: 2px solid #cccccc;
+	background-color: #ffffff;
+}
+
+#about
+{
+	clear: both;
+	margin: 0;
+	padding: 5px;
+	border-top: 2px solid #cccccc;
+	background-color: #ffffff;
+}
+
+@media print {
+	body { 
+		font: 12pt "Times New Roman", "TimeNR", Times, serif;
+	}
+	a { font-weight:bold; color: #004080; text-decoration: underline; }
+	
+	#main
	{
		background-color: #ffffff;
		border-left: 0px;
	}
	
+	#container
	{
		margin-left: 2%;
		margin-right: 2%;
		background-color: #ffffff;
	}
+	
+	#content
	{
		margin-left: 0px;
		padding: 1em;
		border-left: 0px;
		border-right: 0px;
		background-color: #ffffff;
	}
+	
+	#navigation
	{
		display: none;
+	}
+	pre.example {
+		font-family: "Andale Mono", monospace; 
+		font-size: 10pt;
+		page-break-inside: avoid;
+	}
+}
+
+table.module_list td
+{
+	border-width: 1px;
+	padding: 3px;
+	border-style: solid;
+	border-color: #cccccc;
+}
+table.module_list td.name { background-color: #f0f0f0; }
+table.module_list td.summary { width: 100%; }
+
+table.file_list
+{
+	border-width: 1px;
+	border-style: solid;
+	border-color: #cccccc;
+	border-collapse: collapse;
+}
+table.file_list td
+{
+	border-width: 1px;
+	padding: 3px;
+	border-style: solid;
+	border-color: #cccccc;
+}
+table.file_list td.name { background-color: #f0f0f0; }
+table.file_list td.summary { width: 100%; }
+
+
+table.function_list
+{
+	border-width: 1px;
+	border-style: solid;
+	border-color: #cccccc;
+	border-collapse: collapse;
+}
+table.function_list td
+{
+	border-width: 1px;
+	padding: 3px;
+	border-style: solid;
+	border-color: #cccccc;
+}
+table.function_list td.name { background-color: #f0f0f0; }
+table.function_list td.summary { width: 100%; }
+
+
+table.table_list
+{
+	border-width: 1px;
+	border-style: solid;
+	border-color: #cccccc;
+	border-collapse: collapse;
+}
+table.table_list td
+{
+	border-width: 1px;
+	padding: 3px;
+	border-style: solid;
+	border-color: #cccccc;
+}
+table.table_list td.name { background-color: #f0f0f0; }
+table.table_list td.summary { width: 100%; }
+
+dl.function dt {border-top: 1px solid #ccc; padding-top: 1em;}
+dl.function dd {padding-bottom: 1em;}
+dl.function h3 {padding-top: 1em; margin: 0; font-size: medium;}
+
+dl.table dt {border-top: 1px solid #ccc; padding-top: 1em;}
+dl.table dd {padding-bottom: 1em;}
+dl.table h3 {padding: 0; margin: 0; font-size: medium;}
+
+#TODO: make module_list, file_list, function_list, table_list inherit from a list
+

+ 1 - 0
注释例子/b.bat

@@ -0,0 +1 @@
+lua.exe "%LUA_DEV%\lua\luadoc_start.lua" -d "Docs" *

+ 24 - 0
注释例子/test.lua

@@ -0,0 +1,24 @@
+--- 这是一个测试类
+--@class table
+--@name CTestClass
+--@field name 这里的重要的成员参数说明
+local CTestClass = __newclass "CTestClass"
+
+
+--- 创建对象
+--@param id 根据id创建类
+function CTestClass:new(id)
+	local obj = 
+	{
+		name = "", 
+	}
+	setmetatable(obj, CTestClass)
+	return obj
+end
+
+--- 成员函数
+--@param p1 参数1说明
+--@see CTestClass:func
+function CTestClass:func(p1)
+
+end

+ 45 - 0
类模拟/类实现示例.lua

@@ -0,0 +1,45 @@
+--[[
+-- 测试类说明
+-- 这里演示类的写法,单类,不参与继承的写法
+--]]
+
+
+local CFather = require "CFather"
+local setmetatable = setmetatable -- 不要忘记,创建对象不需要查全局表
+
+--@brief 这里是创建类
+local CTestClass = __newclass "CTestClass"
+
+--[[
+-- 如果该类默认有数据可以这样的写法:
+local CTestClass = __newclass(
+"CTestClass",
+{
+	key1 = value1,
+	key2 = value2
+}
+]]
+
+-- 如果需要继承CFather, 特别注意 CFather的dofile必须在这之前
+CTestClass:extend(CFather)
+
+
+--@brief 创建对象接口
+function CTestClass:new()
+	local obj = CFather:new()
+	--obj.name = value
+	
+	setmetatable(obj, self)
+	return obj
+end
+
+---------------------------------------------------------
+--以下添加成员函数
+
+--@brief 定义成员函数
+function CTestClass:func()
+end
+
+
+--以上添加成员函数
+---------------------------------------------------------

+ 24 - 0
组合判断分离判断效率对比/t.lua

@@ -0,0 +1,24 @@
+local b = false
+local b1 = true
+local x
+local t = os.clock()
+for i = 1, 1000000 do
+	if b then
+		if b1 then
+			x = 1
+		end
+	end
+end
+print("1: " ,os.clock() - t)
+
+
+t = os.clock()
+for i = 1, 1000000 do
+	if b and b1 then
+		x = 1
+	end
+end
+print("2: " ,os.clock() - t)
+
+
+os.execute("PAUSE")

+ 21 - 0
表内容重复定义/t.lua

@@ -0,0 +1,21 @@
+local t1 = {}
+
+local s_t = {}
+
+function func(o, k, v)
+	print(o, k, v)
+	if t1[k] then
+		print("error: msg define repeat! type:" .. k)
+	end
+	t1[k] = v
+end
+local m = {__newindex = func}
+setmetatable(s_t, m)
+
+
+s_t.name = "test"
+s_t.name = 2
+
+print(t1.name)
+
+os.execute("PAUSE")

+ 37 - 0
表定义性能对比/t.lua

@@ -0,0 +1,37 @@
+function new1()
+	local obj ={}
+	obj.name1 = 1
+	obj.name2 = 2
+	obj.name3 = "x"
+	obj.name4 = {}
+	obj.name5 = nil
+	return obj
+end
+
+function new2()
+	local obj =
+	{
+		name1 = 1,
+		name2 = 2,
+		name3 = "x",
+		name4 = {},
+		name4 = nil
+	}
+	return obj
+end
+
+
+local t = os.clock()
+for i = 1, 100000 do
+	new1()
+end
+print("new1: " ,os.clock() - t)
+
+
+t = os.clock()
+for i = 1, 100000 do
+	new2()
+end
+print("new2: " ,os.clock() - t)
+
+os.execute("PAUSE")

+ 27 - 0
表数据多是否影响效率测试/t.lua

@@ -0,0 +1,27 @@
+
+local t1 = {}
+
+for i = 1, 100 do
+	t1[i + i] = i
+end
+
+local t2 = {}
+for i = 1, 200 do
+	t2[i + i] = i
+end
+
+local t = os.clock()
+for i = 1, 10000000 do
+	t1[50] = 0
+end
+print(os.clock() - t)
+
+
+t = os.clock()
+for i = 1, 10000000 do
+	t2[50] = 0
+end
+print(os.clock() - t)
+
+
+os.execute("PAUSE")

+ 0 - 0
遍历表方式性能对比/t.lua