Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. -- Copy Class
  2. local copyClass = {}
  3.  
  4. copyClass.func_1 = function() print(i) end
  5. copyClass.func_2 = function() print(i) end
  6. copyClass.func_3 = function() print(i) end
  7. copyClass.func_4 = function() print(i) end
  8. copyClass.func_5 = function() print(i) end
  9. copyClass.func_6 = function() print(i) end
  10. copyClass.func_7 = function() print(i) end
  11. copyClass.func_8 = function() print(i) end
  12. copyClass.func_9 = function() print(i) end
  13. copyClass.func_10 = function() print(i) end
  14. copyClass.func_11 = function() print(i) end
  15. copyClass.func_12 = function() print(i) end
  16. copyClass.func_13 = function() print(i) end
  17. copyClass.func_14 = function() print(i) end
  18. copyClass.func_15 = function() print(i) end
  19. copyClass.func_16 = function() print(i) end
  20. copyClass.func_17 = function() print(i) end
  21. copyClass.func_18 = function() print(i) end
  22. copyClass.func_19 = function() print(i) end
  23. copyClass.func_20 = function() print(i) end
  24.  
  25. function copyClass.new()
  26. local obj = {}
  27.  
  28. obj.func_1 = copyClass.func_1
  29. obj.func_2 = copyClass.func_2
  30. obj.func_3 = copyClass.func_3
  31. obj.func_4 = copyClass.func_4
  32. obj.func_5 = copyClass.func_5
  33. obj.func_6 = copyClass.func_6
  34. obj.func_7 = copyClass.func_7
  35. obj.func_8 = copyClass.func_8
  36. obj.func_9 = copyClass.func_9
  37. obj.func_10 = copyClass.func_10
  38. obj.func_11 = copyClass.func_11
  39. obj.func_12 = copyClass.func_12
  40. obj.func_13 = copyClass.func_13
  41. obj.func_14 = copyClass.func_14
  42. obj.func_15 = copyClass.func_15
  43. obj.func_16 = copyClass.func_16
  44. obj.func_17 = copyClass.func_17
  45. obj.func_18 = copyClass.func_18
  46. obj.func_19 = copyClass.func_19
  47. obj.func_20 = copyClass.func_20
  48.  
  49. return obj
  50. end
  51.  
  52. -- Inherit Class
  53. local inheritClass = {}
  54. inheritClass.__index = inheritClass
  55.  
  56. inheritClass.func_1 = function() print(i) end
  57. inheritClass.func_2 = function() print(i) end
  58. inheritClass.func_3 = function() print(i) end
  59. inheritClass.func_4 = function() print(i) end
  60. inheritClass.func_5 = function() print(i) end
  61. inheritClass.func_6 = function() print(i) end
  62. inheritClass.func_7 = function() print(i) end
  63. inheritClass.func_8 = function() print(i) end
  64. inheritClass.func_9 = function() print(i) end
  65. inheritClass.func_10 = function() print(i) end
  66. inheritClass.func_11 = function() print(i) end
  67. inheritClass.func_12 = function() print(i) end
  68. inheritClass.func_13 = function() print(i) end
  69. inheritClass.func_14 = function() print(i) end
  70. inheritClass.func_15 = function() print(i) end
  71. inheritClass.func_16 = function() print(i) end
  72. inheritClass.func_17 = function() print(i) end
  73. inheritClass.func_18 = function() print(i) end
  74. inheritClass.func_19 = function() print(i) end
  75. inheritClass.func_20 = function() print(i) end
  76.  
  77. function inheritClass.new()
  78. local obj = setmetatable({}, inheritClass)
  79.  
  80. return obj
  81. end
  82.  
  83. -- Tables for holding reference
  84. local copyObjects = {}
  85. local inheritObjects = {}
  86.  
  87. -- Test start
  88. collectgarbage()
  89. local m1 = collectgarbage("count")
  90. local t1 = love.timer.getTime()
  91.  
  92. -- Copy Test
  93. for i = 1, 100000 do
  94. copyObjects[i] = copyClass.new()
  95. end
  96.  
  97. collectgarbage()
  98. local m2 = collectgarbage("count")
  99. local t2 = love.timer.getTime()
  100.  
  101. -- Inherit Test
  102. for i = 1, 100000 do
  103. inheritObjects[i] = inheritClass.new()
  104. end
  105.  
  106. collectgarbage()
  107. local m3 = collectgarbage("count")
  108. local t3 = love.timer.getTime()
  109.  
  110. -- Output
  111. print("Copy memory used: "..m2-m1.." kB in: " ..t2-t1)
  112. print("Inherit memory used: "..m3-m2.." kB in " ..t3-t2)
  113.  
  114. love.event.quit()
  115.  
  116. --[[
  117. Copy memory used: 79148.728515625 kb in: 2.4352197502158
  118. Inherit memory used: 4150.9990234375 kb in 0.029863576521166
  119. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement