2023-12-08 23:42:54 +08:00
|
|
|
local function prequire(name) local success, result = pcall(require, name); return if success then result else nil end
|
|
|
|
local bench = script and require(script.Parent.bench_support) or prequire("bench_support") or require("../bench_support")
|
2023-08-05 01:01:35 +08:00
|
|
|
|
|
|
|
bench.runCode(function()
|
|
|
|
for j=1,1e6 do
|
|
|
|
local _ = "j=" .. tostring(j)
|
|
|
|
end
|
|
|
|
end, "interp: tostring")
|
|
|
|
|
|
|
|
bench.runCode(function()
|
|
|
|
for j=1,1e6 do
|
|
|
|
local _ = "j=" .. j
|
|
|
|
end
|
|
|
|
end, "interp: concat")
|
|
|
|
|
|
|
|
bench.runCode(function()
|
|
|
|
for j=1,1e6 do
|
|
|
|
local _ = string.format("j=%f", j)
|
|
|
|
end
|
|
|
|
end, "interp: %f format")
|
|
|
|
|
|
|
|
bench.runCode(function()
|
|
|
|
for j=1,1e6 do
|
|
|
|
local _ = string.format("j=%d", j)
|
|
|
|
end
|
|
|
|
end, "interp: %d format")
|
|
|
|
|
|
|
|
bench.runCode(function()
|
|
|
|
for j=1,1e6 do
|
|
|
|
local _ = string.format("j=%*", j)
|
|
|
|
end
|
|
|
|
end, "interp: %* format")
|
|
|
|
|
|
|
|
bench.runCode(function()
|
|
|
|
for j=1,1e6 do
|
|
|
|
local _ = `j={j}`
|
|
|
|
end
|
|
|
|
end, "interp: interp number")
|
|
|
|
|
2023-08-11 20:55:30 +08:00
|
|
|
bench.runCode(function()
|
|
|
|
local ok = "hello!"
|
|
|
|
for j=1,1e6 do
|
|
|
|
local _ = string.format("j=%s", ok)
|
|
|
|
end
|
|
|
|
end, "interp: %s format")
|
|
|
|
|
2023-08-05 01:01:35 +08:00
|
|
|
bench.runCode(function()
|
|
|
|
local ok = "hello!"
|
|
|
|
for j=1,1e6 do
|
|
|
|
local _ = `j={ok}`
|
|
|
|
end
|
|
|
|
end, "interp: interp string")
|