Advertisement
Techmo

Gmod Profiler Example

Sep 5th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. ProfilerInit(100) -- Initalizes the profiler, and starts the watchdog timer. Allocates memory for 100 unique function profiles. We are only using 1.
  2.  
  3. local function ResetTimer()
  4.     ProfilerKick()
  5. end
  6.  
  7. timer.Create("ProfilerWatchdog", 1, 0, ResetTimer) -- Reset the watchdog timer every second
  8. -- The timer kick interval can be decreased, but very small values will start to affect performance.
  9. -- When this timer runs out, all time samples for each profile in memory will be written to the "profiles" folder in the root server directory.
  10.  
  11.  
  12. local loop_profile = CreateProfile("CoolLoop") -- Create a new function profile.
  13.  
  14. function longloop()
  15.     i = 0
  16.     while i < 10000 do
  17.         i = i + 1
  18.     end
  19. end
  20.  
  21. print("Test started")
  22.  
  23. j = 0
  24.  
  25. -- Lets get 1000 time samples for our function, and store it in the loop_profile
  26. while j < 1000 do
  27.     StartProfile(loop_profile)
  28.     longloop()
  29.     StopProfile(loop_profile)
  30.     j = j + 1
  31. end
  32.  
  33. print("Test done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement