Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/bench/micro_tests/test_StringInterp.lua
2725 views
1
local function prequire(name) local success, result = pcall(require, name); return success and result end
2
local bench = script and require(script.Parent.bench_support) or prequire("bench_support") or require("../bench_support")
3
4
bench.runCode(function()
5
for j=1,1e6 do
6
local _ = "j=" .. tostring(j)
7
end
8
end, "interp: tostring")
9
10
bench.runCode(function()
11
for j=1,1e6 do
12
local _ = "j=" .. j
13
end
14
end, "interp: concat")
15
16
bench.runCode(function()
17
for j=1,1e6 do
18
local _ = string.format("j=%f", j)
19
end
20
end, "interp: %f format")
21
22
bench.runCode(function()
23
for j=1,1e6 do
24
local _ = string.format("j=%d", j)
25
end
26
end, "interp: %d format")
27
28
bench.runCode(function()
29
for j=1,1e6 do
30
local _ = string.format("j=%*", j)
31
end
32
end, "interp: %* format")
33
34
bench.runCode(function()
35
for j=1,1e6 do
36
local _ = `j={j}`
37
end
38
end, "interp: interp number")
39
40
bench.runCode(function()
41
local ok = "hello!"
42
for j=1,1e6 do
43
local _ = string.format("j=%s", ok)
44
end
45
end, "interp: %s format")
46
47
bench.runCode(function()
48
local ok = "hello!"
49
for j=1,1e6 do
50
local _ = `j={ok}`
51
end
52
end, "interp: interp string")
53