aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-18 15:16:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-18 15:16:26 -0300
commit3e9dbe143d3338f5f13a5e421ea593adff482da0 (patch)
treece070c600970d216f3a68c78ae9e55d8048ec4ff /testes
parent4a8e48086433ad12f2991c07f3064278714fd0f1 (diff)
downloadlua-3e9dbe143d3338f5f13a5e421ea593adff482da0.tar.gz
lua-3e9dbe143d3338f5f13a5e421ea593adff482da0.tar.bz2
lua-3e9dbe143d3338f5f13a5e421ea593adff482da0.zip
New function 'table.create'
Creates a table preallocating memory. (It just exports to Lua the API function 'lua_createtable'.)
Diffstat (limited to 'testes')
-rw-r--r--testes/sort.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/testes/sort.lua b/testes/sort.lua
index 40bb2d8a..45014652 100644
--- a/testes/sort.lua
+++ b/testes/sort.lua
@@ -3,6 +3,27 @@
3 3
4print "testing (parts of) table library" 4print "testing (parts of) table library"
5 5
6do print "testing 'table.create'"
7 collectgarbage()
8 local m = collectgarbage("count") * 1024
9 local t = table.create(10000)
10 local memdiff = collectgarbage("count") * 1024 - m
11 assert(memdiff > 10000 * 4)
12 for i = 1, 20 do
13 assert(#t == i - 1)
14 t[i] = 0
15 end
16 assert(not T or T.querytab(t) == 10000)
17 t = nil
18 collectgarbage()
19 m = collectgarbage("count") * 1024
20 t = table.create(0, 1024)
21 memdiff = collectgarbage("count") * 1024 - m
22 assert(memdiff > 1024 * 12)
23 assert(not T or select(2, T.querytab(t)) == 1024)
24end
25
26
6print "testing unpack" 27print "testing unpack"
7 28
8local unpack = table.unpack 29local unpack = table.unpack