FANDOM


-- Benchmark Test

draw.setscreen(1) -- Variables local width, height = draw.getport() local cenx, ceny = width/2, height/2 local screenmax = math.max(width, height) local screenmin = math.min(width, height) local clock = os.clock local sleep = sys.sleep local Fps = 1/30

-- local functions -- local line = draw.line local circle = draw.circle local fillcircle = draw.fillcircle local rect = draw.rect local fillrect = draw.fillrect

Tests = {} DrawObjects = {}

local GlobalSpeedTable = {}

-- Objects to draw in the test -- function DrawObjects.Lines()

  draw.line(0, ceny, width, ceny, draw.blue)

end

function DrawObjects.Squares()

  rect(0, 0, screenmin, screenmax, draw.blue)

end

function DrawObjects.FilledSquares()

  fillrect(0, 0, screenmin, screenmax, draw.blue)

end

function DrawObjects.Circles()

  circle(cenx, ceny, screenmin/2, draw.blue)

end

function DrawObjects.FilledCircles()

  fillcircle(cenx, ceny, screenmin/2, draw.blue)

end

function DrawObjectsSubTest(functVal)

  local Score = 0
  local startTime = clock()
  local startTime2, endTime = 0, 0
  local ObjectsPerSecond, OPS = 6000, 6000
  local DrawOPS = 200
  -- Draw a frame
  while clock() < startTime + 2 do
     draw.beginframe()
     draw.clear()
     startTime2 = clock()
     for i=1, DrawOPS do
        functVal()
     end
     endTime = clock()
     ObjectsPerSecond = DrawOPS/(endTime - startTime2)
     OPS = math.floor(ObjectsPerSecond)
     DrawOPS = math.floor(OPS*Fps)
     draw.string(DrawOPS.."/"..OPS, 0, height - 24, draw.black)
     draw.endframe()
     --sleep(10)
  end
  Score = ObjectsPerSecond
  return math.floor(Score*10)/10

end

-- Drawn Items Per Second Testing function Tests.DrawnObjectsPerSecond()

  local ScoreTable = {}
  local DrawObjectsSubTest = DrawObjectsSubTest
  for k, v in pairs(DrawObjects) do
     ScoreTable[k] = DrawObjectsSubTest(v)
  end
  return ScoreTable

end

function SaveImage(Size)

  Size = Size + 1
  local Save = tostring("Images/Grid"..8*Size.."x"..8*Size..".png")
  draw.imagesave(Save, 8, 8, 8*Size, 8*Size)

end

-- Generate Images -- function GenerateImages()

  local lfs = require "lfs"
  lfs.mkdir("Images")
  draw.beginframe()
  draw.clear()
  local color = {}
  local odd = false
  local oddy = false
  for y=1, 16 do
     oddy = not oddy
     odd = not oddy
     for x=1, 16 do
        odd = not odd
        if odd then
           color = draw.blue
        else
           color = draw.lightgray
        end
        draw.fillrect(x*8, y*8, (x + 1)*8, (y + 1)*8, color)
     end
  end
  for i=1, 8 do
     SaveImage(i)
  end
  draw.endframe()

end

local DrawImages = {

  "Images/Grid16x16.png",
  "Images/Grid24x24.png",
  "Images/Grid32x32.png",
  "Images/Grid48x48.png"

}

function DrawImagesSubTest(imageVal)

  local Score = 0
  local startTime = clock()
  local startTime2, endTime = 0, 0
  local ObjectsPerSecond, OPS = 6000, 6000
  local DrawOPS = 200
  -- Draw a frame
  while clock() < startTime + 2 do
     draw.beginframe()
     draw.clear()
     startTime2 = clock()
     for i=1, DrawOPS do
        draw.image(imageVal, cenx, ceny)
     end
     endTime = clock()
     ObjectsPerSecond = DrawOPS/(endTime - startTime2)
     OPS = math.floor(ObjectsPerSecond)
     DrawOPS = math.floor(OPS*Fps)
     draw.string(DrawOPS.."/"..OPS, 0, height - 24, draw.black)
     draw.endframe()
     --sleep(10)
  end
  Score = ObjectsPerSecond
  return math.floor(Score*10)/10

end

-- Saved Image Testing function Tests.Images()

  local ScoreTable = {}
  local DrawImagesSubTest = DrawImagesSubTest
  for k, v in pairs(DrawImages) do
     ScoreTable[k] = DrawImagesSubTest(v)
  end
  return ScoreTable

end

function PrintTable(Table)

  for k, v in pairs(Table) do
     print(k, v)
  end

end

function ReturnFinalScore(...)

  local values, totalval = 0, 0
  local args = {...}
  for k, v in pairs(args) do
     for k2, v2 in pairs(v) do
        values = values + 1
        totalval = totalval + v2
     end
  end
  return math.floor(totalval/values)

end

--GenerateImages()

local ScoreTab1 = Tests.DrawnObjectsPerSecond() local ScoreTab2 = Tests.Images()

-- Print Results print("Object Test Results") PrintTable(ScoreTab1)

print("Image Test Results") PrintTable(ScoreTab2)

local FinalScore = ReturnFinalScore(ScoreTab1, ScoreTab2) print("The Final Score is: "..FinalScore..".")

-- End of File.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.