Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Classes
- local Person_Class = {}
- Person_Class.__index = Person_Class
- function Person_Class:live()
- self.happiness = self.happiness - 10
- end
- local Employee_Class = setmetatable({}, Person_Class)
- Employee_Class.__index = Employee_Class
- function Employee_Class:payTaxes()
- self.money = self.money - 10
- end
- local Programmer_Class = setmetatable({}, Employee_Class)
- Programmer_Class.__index = Programmer_Class
- function Programmer_Class:program()
- self.frustration = self.frustration + 10
- end
- -- Components
- local Person_Component = {}
- Person_Component.objects = {}
- function Person_Component.add(o)
- Person_Component.objects[#Person_Component.objects + 1] = o
- end
- function Person_Component.update()
- for i = 1, #Person_Component.objects do
- local o = Person_Component.objects[i]
- o.happiness = o.happiness - 10
- end
- end
- local Employee_Component = {}
- Employee_Component.objects = {}
- function Employee_Component.add(o)
- Employee_Component.objects[#Employee_Component.objects + 1] = o
- end
- function Employee_Component.update()
- for i = 1, #Employee_Component.objects do
- local o = Employee_Component.objects[i]
- o.money = o.money - 10
- end
- end
- local Programmer_Component = {}
- Programmer_Component.objects = {}
- function Programmer_Component.add(o)
- Programmer_Component.objects[#Programmer_Component.objects + 1] = o
- end
- function Programmer_Component.update()
- for i = 1, #Programmer_Component.objects do
- local o = Programmer_Component.objects[i]
- o.frustration = o.frustration + 10
- end
- end
- -- Initial creation
- local objects = {}
- for i = 1, 500000 do
- local o = {
- happiness = 100,
- money = 0,
- frustration = 0,
- }
- objects[i] = setmetatable(o, Programmer_Class)
- Person_Component.add(o)
- Employee_Component.add(o)
- Programmer_Component.add(o)
- end
- -- Actual test
- local s1 = love.timer.getTime()
- for i = 1, #objects do
- local o = objects[i]
- o:live()
- o:payTaxes()
- o:program()
- end
- local e1 = love.timer.getTime()
- local s2 = love.timer.getTime()
- Person_Component.update()
- Employee_Component.update()
- Programmer_Component.update()
- local e2 = love.timer.getTime()
- print(e1 - s1)
- print(e2 - s2)
Advertisement
Add Comment
Please, Sign In to add comment