Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Copy Class
- local copyClass = {}
- copyClass.func_1 = function() print(i) end
- copyClass.func_2 = function() print(i) end
- copyClass.func_3 = function() print(i) end
- copyClass.func_4 = function() print(i) end
- copyClass.func_5 = function() print(i) end
- copyClass.func_6 = function() print(i) end
- copyClass.func_7 = function() print(i) end
- copyClass.func_8 = function() print(i) end
- copyClass.func_9 = function() print(i) end
- copyClass.func_10 = function() print(i) end
- copyClass.func_11 = function() print(i) end
- copyClass.func_12 = function() print(i) end
- copyClass.func_13 = function() print(i) end
- copyClass.func_14 = function() print(i) end
- copyClass.func_15 = function() print(i) end
- copyClass.func_16 = function() print(i) end
- copyClass.func_17 = function() print(i) end
- copyClass.func_18 = function() print(i) end
- copyClass.func_19 = function() print(i) end
- copyClass.func_20 = function() print(i) end
- function copyClass.new()
- local obj = {}
- obj.func_1 = copyClass.func_1
- obj.func_2 = copyClass.func_2
- obj.func_3 = copyClass.func_3
- obj.func_4 = copyClass.func_4
- obj.func_5 = copyClass.func_5
- obj.func_6 = copyClass.func_6
- obj.func_7 = copyClass.func_7
- obj.func_8 = copyClass.func_8
- obj.func_9 = copyClass.func_9
- obj.func_10 = copyClass.func_10
- obj.func_11 = copyClass.func_11
- obj.func_12 = copyClass.func_12
- obj.func_13 = copyClass.func_13
- obj.func_14 = copyClass.func_14
- obj.func_15 = copyClass.func_15
- obj.func_16 = copyClass.func_16
- obj.func_17 = copyClass.func_17
- obj.func_18 = copyClass.func_18
- obj.func_19 = copyClass.func_19
- obj.func_20 = copyClass.func_20
- return obj
- end
- -- Inherit Class
- local inheritClass = {}
- inheritClass.__index = inheritClass
- inheritClass.func_1 = function() print(i) end
- inheritClass.func_2 = function() print(i) end
- inheritClass.func_3 = function() print(i) end
- inheritClass.func_4 = function() print(i) end
- inheritClass.func_5 = function() print(i) end
- inheritClass.func_6 = function() print(i) end
- inheritClass.func_7 = function() print(i) end
- inheritClass.func_8 = function() print(i) end
- inheritClass.func_9 = function() print(i) end
- inheritClass.func_10 = function() print(i) end
- inheritClass.func_11 = function() print(i) end
- inheritClass.func_12 = function() print(i) end
- inheritClass.func_13 = function() print(i) end
- inheritClass.func_14 = function() print(i) end
- inheritClass.func_15 = function() print(i) end
- inheritClass.func_16 = function() print(i) end
- inheritClass.func_17 = function() print(i) end
- inheritClass.func_18 = function() print(i) end
- inheritClass.func_19 = function() print(i) end
- inheritClass.func_20 = function() print(i) end
- function inheritClass.new()
- local obj = setmetatable({}, inheritClass)
- return obj
- end
- -- Tables for holding reference
- local copyObjects = {}
- local inheritObjects = {}
- -- Test start
- collectgarbage()
- local m1 = collectgarbage("count")
- local t1 = love.timer.getTime()
- -- Copy Test
- for i = 1, 100000 do
- copyObjects[i] = copyClass.new()
- end
- collectgarbage()
- local m2 = collectgarbage("count")
- local t2 = love.timer.getTime()
- -- Inherit Test
- for i = 1, 100000 do
- inheritObjects[i] = inheritClass.new()
- end
- collectgarbage()
- local m3 = collectgarbage("count")
- local t3 = love.timer.getTime()
- -- Output
- print("Copy memory used: "..m2-m1.." kB in: " ..t2-t1)
- print("Inherit memory used: "..m3-m2.." kB in " ..t3-t2)
- love.event.quit()
- --[[
- Copy memory used: 79148.728515625 kb in: 2.4352197502158
- Inherit memory used: 4150.9990234375 kb in 0.029863576521166
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement