Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local optimizationFlags = {"fold", "cse", "dce", "narrow", "loop", "fwd", "dse", "abc", "sink", "fuse"}
- -- Constant Folding, Simplifications and Reassociation
- -- Common-Subexpression Elimination
- -- Dead-Code Elimination
- -- Narrowing of numbers to integers
- -- Loop Optimizations (code hoisting)
- -- Load Forwarding (L2L) and Store Forwarding (S2L)
- -- Dead-Store Elimination
- -- Array Bounds Check Elimination
- -- Allocation/Store Sinking
- -- Fusion of operands into instructions
- local function runBench(iter)
- local fastestBench = {"initial", math.huge}
- function RunBenchmark(var, iterations, func)
- local start = SysTime()
- local tbl = {}
- for i = 1, iterations do
- func(tbl)
- end
- local duration = SysTime() - start
- --print("Benchmark completed in " .. duration .. " seconds.")
- --print("Average time per iteration: " .. duration / iterations .. " seconds.")
- if duration < fastestBench[2] then
- fastestBench = {var, duration}
- end
- return duration
- end
- --print("[=============Bench Start=============]")
- local istable = istable
- local function istab(var)
- return istable(var)
- end
- --these two have function overhead, so not very good :(
- jit.off(istab)
- --print("\n\njitOff")
- RunBenchmark("jit.off(istab)", iter, istab)
- jit.on(istab)
- --print("\n\n\n\n\njitOn")
- RunBenchmark("jit.on(istab)", iter, istab)
- jit.off()
- --print("\n\n\n\n\njitOffFully")
- RunBenchmark("jit.off()", iter, istable)
- jit.on()
- --print("\n\n\n\n\njitOnFully")
- RunBenchmark("jit.on()", iter, istable)
- --print("\n\n[=============Fastest Bench=============]")
- --print(fastestBench[1] , fastestBench[2])
- --print("\n\n[=============Bench End=============]")
- return fastestBench[1], fastestBench[2]
- end
- print("Architecture:", jit.arch)
- print("Version:", jit.version)
- local benchInfo = {}
- local benchNum = 20000
- local totalBenches = 10000
- jit.opt.start(1)
- for i = 1, totalBenches do
- local name, time = runBench(benchNum)
- benchInfo[name] = (benchInfo[name] or 0) + 1
- end
- local fastestBench = {"default", 0}
- print("\n\n[===============Bench Info (O1)===============]")
- for k, v in pairs(benchInfo) do
- print(k, "fastest", v, "times.")
- if v > fastestBench[2] then
- fastestBench = {k, v}
- end
- end
- print("\nFastest Bench", fastestBench[1])
- print("\n\n[=============Bench Info End (O1)=============]")
- benchInfo = {}
- jit.opt.start(2)
- for i = 1, totalBenches do
- local name, time = runBench(benchNum)
- benchInfo[name] = (benchInfo[name] or 0) + 1
- end
- fastestBench = {"default", 0}
- print("\n\n[===============Bench Info (O2)===============]")
- for k, v in pairs(benchInfo) do
- print(k, "fastest", v, "times.")
- if v > fastestBench[2] then
- fastestBench = {k, v}
- end
- end
- print("\nFastest Bench", fastestBench[1])
- print("\n\n[=============Bench Info End (O2)=============]")
- benchInfo = {}
- jit.opt.start(3)
- for i = 1, totalBenches do
- local name, time = runBench(benchNum)
- benchInfo[name] = (benchInfo[name] or 0) + 1
- end
- fastestBench = {"default", 0}
- print("\n\n[===============Bench Info (O3)===============]")
- for k, v in pairs(benchInfo) do
- print(k, "fastest", v, "times.")
- if v > fastestBench[2] then
- fastestBench = {k, v}
- end
- end
- print("\nFastest Bench", fastestBench[1])
- print("\n\n[=============Bench Info End (O3)=============]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement