Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Msg,MsgN,math,table=Msg,MsgN,math,table
- Msg("Arithmetic Benchmark 1.0 by Somepotato - ")
- if(luajit) then
- Msg("Using Luajit")
- else
- Msg("Using Lua")
- end
- MsgN(" - Will test arithmetic operators and various functions that should see a speedup in Luajit")
- local iterations=10000000
- MsgN("Iterations set to "..iterations)
- local tests={
- ["+x Test"]=function()
- local ret=-math.huge
- for i=1, iterations do
- ret=i+i
- end
- return true
- end,
- ["Double Precision Validation"] = function()
- for i=0,100 do
- if(tonumber("8.0e-"..i)~=8/(10^i)) then
- Msg("*Failed at "..i.." or 8/"..(8/10^i).." ~= "..(8/10^i).."* ")
- return false
- end
- end
- return true
- end,
- ["/x Test"]=function()
- local ret=0
- for i=1,iterations do
- ret=i+i
- end
- return true
- end,
- ["-x Test"]=function()
- local ret=0
- for i=1,iterations do
- ret=i-i
- end
- return true
- end,
- ["*x Test"]=function()
- local ret=0
- for i=1,iterations do
- ret=i*i
- end
- return true
- end,
- ["^x Test"]=function()
- local ret=0
- for i=1,iterations do
- ret=i^i
- end
- return true
- end,
- [">>x Test"]=function()
- local ret=0
- for i=1,iterations do
- ret=i>>i
- end
- return true
- end,
- ["<<x Test"]=function()
- local ret=0
- for i=1,iterations do
- ret=i<<i
- end
- return true
- end,
- ["Long Bitwise Test"]=function()
- return 1<<31==2147483648 or 2147483648>>31 == 1
- end,
- ["Floating Point Bitwise Test"]=function()
- return 1.5>>2 == 0.375
- end,
- ["Table Insert Test"]=function()
- local tbl={}
- for i=1,iterations do
- table.insert(tbl,i)
- end
- return #tbl==iterations
- end,
- ["_G Lookup"]=function()
- for i=1,iterations do
- local debug = _G["debug"]
- end
- return true
- end,
- ["Global Lookup"]=function()
- for i=1,iterations do
- local debug=debug
- end
- return true
- end,
- ["Comparison Operators Test"]=function()
- for i=1,iterations do
- if not (i<i+1) then return false end
- if not (i+1>i) then return false end
- if not (i<=i+1) then return false end
- if not (i+1>=i) then return false end
- if not (i==(i-1+1)) then return false end
- if not (i~=(i+1)) then return false end
- end
- return true
- end
- }
- MsgN("Performing "..table.Count(tests).." tests now...")
- local start=SysTime()
- local success,failed=0,0
- for k,v in pairs(tests) do
- Msg("Test: "..k..": ")
- local start=SysTime()
- local ret=v()
- local dur=SysTime()-start
- Msg("Test "..(ret and "passed in " or "failed in "))
- MsgN((dur*1000).." milliseconds.")
- if ret then success=success+1 else failed=failed+1 end
- end
- 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