docs improvement
This commit is contained in:
@@ -23,18 +23,18 @@ end
|
||||
|
||||
function TestPerformanceInstrumentation:testTimerStartStop()
|
||||
Performance.startTimer("test_operation")
|
||||
|
||||
|
||||
-- Simulate some work
|
||||
local sum = 0
|
||||
for i = 1, 1000 do
|
||||
sum = sum + i
|
||||
end
|
||||
|
||||
|
||||
local elapsed = Performance.stopTimer("test_operation")
|
||||
|
||||
|
||||
luaunit.assertNotNil(elapsed)
|
||||
luaunit.assertTrue(elapsed >= 0)
|
||||
|
||||
|
||||
local metrics = Performance.getMetrics()
|
||||
luaunit.assertNotNil(metrics.timings["test_operation"])
|
||||
luaunit.assertEquals(metrics.timings["test_operation"].count, 1)
|
||||
@@ -44,13 +44,15 @@ function TestPerformanceInstrumentation:testMultipleTimers()
|
||||
-- Start multiple timers
|
||||
Performance.startTimer("layout")
|
||||
Performance.startTimer("render")
|
||||
|
||||
|
||||
local sum = 0
|
||||
for i = 1, 100 do sum = sum + i end
|
||||
|
||||
for i = 1, 100 do
|
||||
sum = sum + i
|
||||
end
|
||||
|
||||
Performance.stopTimer("layout")
|
||||
Performance.stopTimer("render")
|
||||
|
||||
|
||||
local metrics = Performance.getMetrics()
|
||||
luaunit.assertNotNil(metrics.timings["layout"])
|
||||
luaunit.assertNotNil(metrics.timings["render"])
|
||||
@@ -58,15 +60,15 @@ end
|
||||
|
||||
function TestPerformanceInstrumentation:testFrameTiming()
|
||||
Performance.startFrame()
|
||||
|
||||
|
||||
-- Simulate frame work
|
||||
local sum = 0
|
||||
for i = 1, 1000 do
|
||||
sum = sum + i
|
||||
end
|
||||
|
||||
|
||||
Performance.endFrame()
|
||||
|
||||
|
||||
local frameMetrics = Performance.getFrameMetrics()
|
||||
luaunit.assertNotNil(frameMetrics)
|
||||
luaunit.assertEquals(frameMetrics.frameCount, 1)
|
||||
@@ -77,10 +79,10 @@ function TestPerformanceInstrumentation:testDrawCallCounting()
|
||||
Performance.incrementCounter("draw_calls", 1)
|
||||
Performance.incrementCounter("draw_calls", 1)
|
||||
Performance.incrementCounter("draw_calls", 1)
|
||||
|
||||
|
||||
local counter = Performance.getFrameCounter("draw_calls")
|
||||
luaunit.assertEquals(counter, 3)
|
||||
|
||||
|
||||
-- Reset and check
|
||||
Performance.resetFrameCounters()
|
||||
counter = Performance.getFrameCounter("draw_calls")
|
||||
@@ -89,10 +91,10 @@ end
|
||||
|
||||
function TestPerformanceInstrumentation:testHUDToggle()
|
||||
luaunit.assertFalse(Performance.getConfig().hudEnabled)
|
||||
|
||||
|
||||
Performance.toggleHUD()
|
||||
luaunit.assertTrue(Performance.getConfig().hudEnabled)
|
||||
|
||||
|
||||
Performance.toggleHUD()
|
||||
luaunit.assertFalse(Performance.getConfig().hudEnabled)
|
||||
end
|
||||
@@ -100,10 +102,10 @@ end
|
||||
function TestPerformanceInstrumentation:testEnableDisable()
|
||||
Performance.enable()
|
||||
luaunit.assertTrue(Performance.isEnabled())
|
||||
|
||||
|
||||
Performance.disable()
|
||||
luaunit.assertFalse(Performance.isEnabled())
|
||||
|
||||
|
||||
-- Timers should not record when disabled
|
||||
Performance.startTimer("disabled_test")
|
||||
local elapsed = Performance.stopTimer("disabled_test")
|
||||
@@ -118,12 +120,12 @@ function TestPerformanceInstrumentation:testMeasureFunction()
|
||||
end
|
||||
return sum
|
||||
end
|
||||
|
||||
|
||||
local wrapped = Performance.measure("expensive_op", expensiveOperation)
|
||||
local result = wrapped(1000)
|
||||
|
||||
|
||||
luaunit.assertEquals(result, 500500) -- sum of 1 to 1000
|
||||
|
||||
|
||||
local metrics = Performance.getMetrics()
|
||||
luaunit.assertNotNil(metrics.timings["expensive_op"])
|
||||
luaunit.assertEquals(metrics.timings["expensive_op"].count, 1)
|
||||
@@ -131,7 +133,7 @@ end
|
||||
|
||||
function TestPerformanceInstrumentation:testMemoryTracking()
|
||||
Performance.updateMemory()
|
||||
|
||||
|
||||
local memMetrics = Performance.getMemoryMetrics()
|
||||
luaunit.assertNotNil(memMetrics)
|
||||
luaunit.assertTrue(memMetrics.currentKb > 0)
|
||||
@@ -142,7 +144,7 @@ end
|
||||
function TestPerformanceInstrumentation:testExportJSON()
|
||||
Performance.startTimer("test_op")
|
||||
Performance.stopTimer("test_op")
|
||||
|
||||
|
||||
local json = Performance.exportJSON()
|
||||
luaunit.assertNotNil(json)
|
||||
luaunit.assertTrue(string.find(json, "fps") ~= nil)
|
||||
@@ -152,16 +154,13 @@ end
|
||||
function TestPerformanceInstrumentation:testExportCSV()
|
||||
Performance.startTimer("test_op")
|
||||
Performance.stopTimer("test_op")
|
||||
|
||||
|
||||
local csv = Performance.exportCSV()
|
||||
luaunit.assertNotNil(csv)
|
||||
luaunit.assertTrue(string.find(csv, "Name,Average") ~= nil)
|
||||
luaunit.assertTrue(string.find(csv, "test_op") ~= nil)
|
||||
end
|
||||
|
||||
-- Run tests if executed directly
|
||||
if arg and arg[0]:find("performance_instrumentation_test%.lua$") then
|
||||
if not _G.RUNNING_ALL_TESTS then
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
end
|
||||
|
||||
return TestPerformanceInstrumentation
|
||||
|
||||
Reference in New Issue
Block a user