Somepotato

GLua Benchmark

Oct 14th, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. local Msg,MsgN,math,table=Msg,MsgN,math,table
  2. Msg("Arithmetic Benchmark 1.0 by Somepotato - ")
  3. if(luajit) then
  4.     Msg("Using Luajit")
  5. else
  6.     Msg("Using Lua")
  7. end
  8. MsgN(" - Will test arithmetic operators and various functions that should see a speedup in Luajit")
  9. local iterations=10000000
  10. MsgN("Iterations set to "..iterations)
  11. local tests={
  12.     ["+x Test"]=function()
  13.         local ret=-math.huge
  14.         for i=1, iterations do
  15.             ret=i+i
  16.         end
  17.         return true
  18.     end,
  19.     ["Double Precision Validation"] = function()
  20.         for i=0,100 do
  21.             if(tonumber("8.0e-"..i)~=8/(10^i)) then
  22.                 Msg("*Failed at "..i.." or 8/"..(8/10^i).." ~= "..(8/10^i).."* ")
  23.                 return false
  24.             end
  25.         end
  26.         return true
  27.     end,
  28.     ["/x Test"]=function()
  29.         local ret=0
  30.         for i=1,iterations do
  31.             ret=i+i
  32.         end
  33.         return true
  34.     end,
  35.     ["-x Test"]=function()
  36.         local ret=0
  37.         for i=1,iterations do
  38.             ret=i-i
  39.         end
  40.         return true
  41.     end,
  42.     ["*x Test"]=function()
  43.         local ret=0
  44.         for i=1,iterations do
  45.             ret=i*i
  46.         end
  47.         return true
  48.     end,
  49.     ["^x Test"]=function()
  50.         local ret=0
  51.         for i=1,iterations do
  52.             ret=i^i
  53.         end
  54.         return true
  55.     end,
  56.     [">>x Test"]=function()
  57.         local ret=0
  58.         for i=1,iterations do
  59.             ret=i>>i
  60.         end
  61.         return true
  62.     end,
  63.     ["<<x Test"]=function()
  64.         local ret=0
  65.         for i=1,iterations do
  66.             ret=i<<i
  67.         end
  68.         return true
  69.     end,
  70.     ["Long Bitwise Test"]=function()
  71.         return 1<<31==2147483648 or 2147483648>>31 == 1
  72.     end,
  73.     ["Floating Point Bitwise Test"]=function()
  74.         return 1.5>>2 == 0.375
  75.     end,
  76.     ["Table Insert Test"]=function()
  77.         local tbl={}
  78.         for i=1,iterations do
  79.             table.insert(tbl,i)
  80.         end
  81.         return #tbl==iterations
  82.     end,
  83.     ["_G Lookup"]=function()
  84.         for i=1,iterations do
  85.             local debug = _G["debug"]
  86.         end
  87.         return true
  88.     end,
  89.     ["Global Lookup"]=function()
  90.         for i=1,iterations do
  91.             local debug=debug
  92.         end
  93.         return true
  94.     end,
  95.     ["Comparison Operators Test"]=function()
  96.         for i=1,iterations do
  97.             if not (i<i+1) then return false end
  98.             if not (i+1>i) then return false end
  99.             if not (i<=i+1) then return false end
  100.             if not (i+1>=i) then return false end
  101.             if not (i==(i-1+1)) then return false end
  102.             if not (i~=(i+1)) then return false end
  103.         end
  104.         return true
  105.        
  106.     end
  107. }
  108. MsgN("Performing "..table.Count(tests).." tests now...")
  109. local start=SysTime()
  110. local success,failed=0,0
  111. for k,v in pairs(tests) do
  112.     Msg("Test: "..k..": ")
  113.     local start=SysTime()
  114.     local ret=v()
  115.     local dur=SysTime()-start
  116.     Msg("Test "..(ret and "passed in " or "failed in "))
  117.     MsgN((dur*1000).." milliseconds.")
  118.     if ret then success=success+1 else failed=failed+1 end
  119. end
  120. MsgN("Tests completed in "..(SysTime()-start).." seconds, "..success.." tests passed, "..failed.." tests failed. Ratio: "..(success/failed))
Advertisement
Add Comment
Please, Sign In to add comment