-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArraySnapshotSpeed.lua
69 lines (53 loc) · 1.47 KB
/
ArraySnapshotSpeed.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--[[----------------------------------------------------------
created: 2018-01-02
author: lixianmin
Copyright (C) - All Rights Reserved
------------------------------------------------------------]]
local require, print = require, print
local Time = UnityEngine.Time
function _RunByWatch (repeatCount, method, ...)
local startTime = Time.realtimeSinceStartup
for i=1, repeatCount do
method(...)
end
local endTime = Time.realtimeSinceStartup
local seconds = endTime - startTime
return seconds
end
function table.clonei (src, dest)
if not src then
return
end
dest = dest or {}
local count = #src
for i = 1, count do
dest[i] = src[i]
end
for i = count+1, #dest do
dest[i] = nil
end
return dest
end
function _TestRawArray (rawArray)
for i=1, #rawArray do
local item = rawArray[i]
end
end
function _TestCopyToSnapshot (rawArray, snapshotArray)
table.clonei(rawArray, snapshotArray)
for i=1, #snapshotArray do
local item = snapshotArray[i]
end
end
local rawArray = {}
local snapshotArray = {}
local size = 8192
for i= 1, size do
table.insert(rawArray, i)
end
for i=1, 10 do
local repeatCount = 50
local rawArrayTime = _RunByWatch(repeatCount, _TestRawArray, rawArray)
local copyToSnapshotTime = _RunByWatch(repeatCount, _TestCopyToSnapshot, rawArray, snapshotArray)
print ('============> ratio='..tostring(copyToSnapshotTime/rawArrayTime))
end