Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions bench/roulette.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Russian Roulette simulator
-- This benchmark includes randomness from an external source that can
-- produce non-deterministic performance.
-- See https://github.com/LuaJIT/LuaJIT/issues/218

-- (Let the test harness determine the random seed)
-- math.randomseed(os.time())

local population = 100e6
local live = 0
local die = 0

for i = 1, population do
if math.random(6) == 6 then
die = die + 1
else
live = live + 1
end
end

print(("Survived %d/%d (%.3f%%)"):format(live, population, live*100/(live+die)))