Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/bench/micro_tests/test_Factorial.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
function test()
5
6
function fact (n)
7
if n == 0 then
8
return 1
9
else
10
return n * fact(n-1)
11
end
12
end
13
14
local ts0 = os.clock()
15
for loops=1,500 do
16
for i=1,100 do
17
fact(i)
18
end
19
end
20
local ts1 = os.clock()
21
22
return ts1 - ts0
23
end
24
25
bench.runCode(test, "Factorial")
26