Advertisement
Yogpod

gmod istable benchmark

Jun 27th, 2023
1,436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | None | 0 0
  1. local optimizationFlags = {"fold", "cse", "dce", "narrow", "loop", "fwd", "dse", "abc", "sink", "fuse"}
  2.  
  3. -- Constant Folding, Simplifications and Reassociation
  4. -- Common-Subexpression Elimination
  5. -- Dead-Code Elimination
  6. -- Narrowing of numbers to integers
  7. -- Loop Optimizations (code hoisting)
  8. -- Load Forwarding (L2L) and Store Forwarding (S2L)
  9. -- Dead-Store Elimination
  10. -- Array Bounds Check Elimination
  11. -- Allocation/Store Sinking
  12. -- Fusion of operands into instructions
  13. local function runBench(iter)
  14.     local fastestBench = {"initial", math.huge}
  15.  
  16.     function RunBenchmark(var, iterations, func)
  17.         local start = SysTime()
  18.         local tbl = {}
  19.  
  20.         for i = 1, iterations do
  21.             func(tbl)
  22.         end
  23.  
  24.         local duration = SysTime() - start
  25.  
  26.         --print("Benchmark completed in " .. duration .. " seconds.")
  27.         --print("Average time per iteration: " .. duration / iterations .. " seconds.")
  28.         if duration < fastestBench[2] then
  29.             fastestBench = {var, duration}
  30.         end
  31.  
  32.         return duration
  33.     end
  34.  
  35.     --print("[=============Bench Start=============]")
  36.     local istable = istable
  37.  
  38.     local function istab(var)
  39.         return istable(var)
  40.     end
  41.  
  42.     --these two have function overhead, so not very good :(
  43.     jit.off(istab)
  44.     --print("\n\njitOff")
  45.     RunBenchmark("jit.off(istab)", iter, istab)
  46.     jit.on(istab)
  47.     --print("\n\n\n\n\njitOn")
  48.     RunBenchmark("jit.on(istab)", iter, istab)
  49.     jit.off()
  50.     --print("\n\n\n\n\njitOffFully")
  51.     RunBenchmark("jit.off()", iter, istable)
  52.     jit.on()
  53.     --print("\n\n\n\n\njitOnFully")
  54.     RunBenchmark("jit.on()", iter, istable)
  55.     --print("\n\n[=============Fastest Bench=============]")
  56.     --print(fastestBench[1] , fastestBench[2])
  57.     --print("\n\n[=============Bench End=============]")
  58.  
  59.     return fastestBench[1], fastestBench[2]
  60. end
  61.  
  62. print("Architecture:", jit.arch)
  63. print("Version:", jit.version)
  64.  
  65. local benchInfo = {}
  66.  
  67. local benchNum = 20000
  68. local totalBenches = 10000
  69.  
  70. jit.opt.start(1)
  71. for i = 1, totalBenches do
  72.     local name, time = runBench(benchNum)
  73.     benchInfo[name] = (benchInfo[name] or 0) + 1
  74. end
  75.  
  76. local fastestBench = {"default", 0}
  77.  
  78. print("\n\n[===============Bench Info (O1)===============]")
  79.  
  80. for k, v in pairs(benchInfo) do
  81.     print(k, "fastest", v, "times.")
  82.  
  83.     if v > fastestBench[2] then
  84.         fastestBench = {k, v}
  85.     end
  86. end
  87.  
  88. print("\nFastest Bench", fastestBench[1])
  89. print("\n\n[=============Bench Info End (O1)=============]")
  90.  
  91. benchInfo = {}
  92.  
  93. jit.opt.start(2)
  94. for i = 1, totalBenches do
  95.     local name, time = runBench(benchNum)
  96.     benchInfo[name] = (benchInfo[name] or 0) + 1
  97. end
  98.  
  99. fastestBench = {"default", 0}
  100.  
  101. print("\n\n[===============Bench Info (O2)===============]")
  102.  
  103. for k, v in pairs(benchInfo) do
  104.     print(k, "fastest", v, "times.")
  105.  
  106.     if v > fastestBench[2] then
  107.         fastestBench = {k, v}
  108.     end
  109. end
  110.  
  111. print("\nFastest Bench", fastestBench[1])
  112. print("\n\n[=============Bench Info End (O2)=============]")
  113.  
  114. benchInfo = {}
  115.  
  116. jit.opt.start(3)
  117. for i = 1, totalBenches do
  118.     local name, time = runBench(benchNum)
  119.     benchInfo[name] = (benchInfo[name] or 0) + 1
  120. end
  121.  
  122. fastestBench = {"default", 0}
  123.  
  124. print("\n\n[===============Bench Info (O3)===============]")
  125.  
  126. for k, v in pairs(benchInfo) do
  127.     print(k, "fastest", v, "times.")
  128.  
  129.     if v > fastestBench[2] then
  130.         fastestBench = {k, v}
  131.     end
  132. end
  133.  
  134. print("\nFastest Bench", fastestBench[1])
  135. print("\n\n[=============Bench Info End (O3)=============]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement