local e=tonumber(arg and arg[1])or 1000 local V,l=e,2/e local t,S=50,4.0 print("\080\052\n",e," ",V,"\n")local o=os.clock()for o=0,V-1,1 do local j=(2*o)/V-1 for V=0,e-1,8 do local o=0 local g=V+7 for e=V,g<e and g or e-1,1 do o=o+o local V,g,F,G=.0,.0,.0,.0 local R=e*l-1.5 for e=1,t,1 do local l=V*g V=(F-G)+R g=(l+l)+j F=V*V G=g*g if F+G>S then o=o+1 break end end end if g>=e then for e=e,g,1 do o=(o+o)+1 end end end end print(os.clock()-o)
-- The Computer Language Benchmarks Game
-- https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
-- contributed by Mike Pall

local width = tonumber(arg and arg[1]) or 1000
local height, wscale = width, 2/width
local m, limit2 = 50, 4.0

print("P4\n", width, " ", height, "\n")

local start = os.clock()

for y=0,height-1 do
  local Ci = 2*y / height - 1
  for xb=0,width-1,8 do
    local bits = 0
    local xbb = xb+7
    for x=xb,xbb < width and xbb or width-1 do
      bits = bits + bits
      local Zr, Zi, Zrq, Ziq = 0.0, 0.0, 0.0, 0.0
      local Cr = x * wscale - 1.5
      for i=1,m do
        local Zri = Zr*Zi
        Zr = Zrq - Ziq + Cr
        Zi = Zri + Zri + Ci
        Zrq = Zr*Zr
        Ziq = Zi*Zi
        if Zrq + Ziq > limit2 then
          bits = bits + 1
          break
        end
      end
    end
    if xbb >= width then
      for x=width,xbb do bits = bits + bits + 1 end
    end
    -- print(string.char(255-bits))
  end
end

print(os.clock() - start)