-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathperformanceTest.lua
More file actions
176 lines (133 loc) · 5.69 KB
/
performanceTest.lua
File metadata and controls
176 lines (133 loc) · 5.69 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
--performance testing scene.
--Used a couple times to check which logic performs faster on an actual device.
local composer = require( "composer" )
local scene = composer.newScene()
require("UIParts")
require("database")
require("plusCodes")
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
local slowestFunc = "" --name of slow func
local slowestTime = 0 --duration of slowest run
local perfText = "" --displaytext object on screen.
local dbInfo = "" --displaytext value too.
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create( event )
if (debug) then print("Creating perfTest") end
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
end
-- show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
if (debug) then print("showing perftest") end
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
--perfText = display.newText(sceneGroup, "slowest function:", display.contentCenterX, 200, native.systemFont, 20)
local startTime = 0
local endtime = 0
local lastRunTime = 0
local slowestRunTime = 0
local textOptions = {}
textOptions.parent = sceneGroup
textOptions.text = "function Log: "
textOptions.x = display.contentCenterX
textOptions.y = display.contentCenterY
textOptions.width = 700
textOptions.height = 0
textOptions.font = native.systemFont
textOptions.fontSize = 24
perfText = display.newText(textOptions)
textOptions.x = 0
textOptions.y = 0
textOptions.text = "dbData: "
dbInfo = display.newText(textOptions)
dbInfo.anchorX = 0
dbInfo.anchorY = 0
local totalLog = ""
--if (debug) then print("") end
if (debug) then print("Making grid") end
--check creating the display grid
startTime = os.clock()
local cellCollection = {}
CreateSquareGrid(23, 25, sceneGroup, cellCollection)
endtime = os.clock()
lastRunTime = endtime - startTime
if (lastRunTime > slowestTime) then
slowestTime = lastRunTime
slowestFunc = "createGrid-23"
end
totalLog = totalLog .. "createGrid-23" .. lastRunTime .. "|\n"
print("func1 " .. lastRunTime)
--check the updateLocal loops
-- if (currentPlusCode == "") then currentPlusCode = "849VCRXR+9C" end
-- startTime = os.clock()
-- for square = 1, #cellCollection do --this is supposed to be faster than ipairs
-- if VisitedCell(shiftCell(currentPlusCode, cellCollection[square].gridX, cellCollection[square].gridY)) then
-- cellCollection[square].fill = visitedCell
-- else
-- cellCollection[square].fill = unvisitedCell
-- end
-- end
-- endtime = os.clock()
-- lastRunTime = endtime - startTime
-- if (lastRunTime > slowestTime) then
-- slowestTime = lastRunTime
-- slowestFunc = "updateLocal-#cellCollection"
-- end
-- totalLog = totalLog .. "updateLocal-#cellCollection" .. lastRunTime .. "|\n"
-- print("func2 " .. lastRunTime)
-- startTime = os.clock()
-- for a, i in ipairs(cellCollection) do
-- if VisitedCell(shiftCell(currentPlusCode, i.gridX, i.gridY)) then
-- i.fill = visitedCell
-- else
-- i.fill = unvisitedCell
-- end
-- end
-- endtime = os.clock()
-- lastRunTime = endtime - startTime
-- if (lastRunTime > slowestTime) then
-- slowestTime = lastRunTime
-- slowestFunc = "updateLocal-ipairs"
-- end
-- totalLog = totalLog .. "updateLocal-ipairs" .. lastRunTime .. "|\n"
-- print("func3 " .. lastRunTime)
perfText.text = perfText.text .. totalLog
local q = Query("SELECT * FROM playerData")[1]
dbInfo.text = "distance:" .. q[2] .." points:" .. q[3] .. " cells:" ..q[4] .. " playtime:" ..q[5] .. " maxSpeed:" ..q[6] .. " totalSpeed:" .. q[7] .. " maxalt:" ..q[8]
dbInfo.text = dbInfo.text .. " minalt:" ..q[9]
end
end
-- hide()
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
end
end
-- destroy()
function scene:destroy( event )
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return scene