run.lua 608 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. local class = require 'middleclass'
  2. time = require 'performance/time'
  3. time('class creation', function()
  4. local A = class('A')
  5. end)
  6. local A = class('A')
  7. time('instance creation', function()
  8. local a = A:new()
  9. end)
  10. function A:foo()
  11. return 1
  12. end
  13. local a = A:new()
  14. time('instance method invocation', function()
  15. a:foo()
  16. end)
  17. local B = class('B', A)
  18. local b = B:new()
  19. time('inherited method invocation', function()
  20. b:foo()
  21. end)
  22. function A.static:bar()
  23. return 2
  24. end
  25. time('class method invocation', function()
  26. A:bar()
  27. end)
  28. time('inherited class method invocation', function()
  29. B:bar()
  30. end)