initialize
This commit is contained in:
62
benchmark.luau
Normal file
62
benchmark.luau
Normal file
@@ -0,0 +1,62 @@
|
||||
local NumRequests = 10000
|
||||
assert(NumRequests >= 10, "please set NumRequests to at least 10")
|
||||
|
||||
local SizeInMiB = 1 -- response packet size
|
||||
|
||||
local ResponseData = string.rep("a", SizeInMiB * 1000000)
|
||||
|
||||
local Net = require("@lune/net")
|
||||
local ServerLib = require("src/Server")
|
||||
local Server = ServerLib.new(3000)
|
||||
|
||||
local RootFolder = Server:registerFolder("root", "/")
|
||||
Server:registerEndpoint(RootFolder, "wow", {
|
||||
method = "GET",
|
||||
path = "/wow",
|
||||
callback = function(request, response)
|
||||
response:setBody(ResponseData):setStatus(200):finish()
|
||||
end
|
||||
})
|
||||
|
||||
Server:start()
|
||||
|
||||
local Completed = 0
|
||||
local Successful = 0
|
||||
|
||||
local Start = os.clock()
|
||||
|
||||
for i = 1, NumRequests do
|
||||
local Response = Net.request({ url = "http://localhost:3000/wow", Method = "GET" })
|
||||
Completed += 1
|
||||
|
||||
if Response.ok and Response.statusCode == 200 then
|
||||
Successful += 1
|
||||
end
|
||||
|
||||
if Completed % (NumRequests / 10) == 0 then
|
||||
print(`Completed [{Completed}/{NumRequests}]`)
|
||||
end
|
||||
end
|
||||
|
||||
local Finish = os.clock()
|
||||
local TimeTook = Finish - Start
|
||||
|
||||
local function Round(Ineger, DecimalPlace)
|
||||
local Multiplier = 10 ^ DecimalPlace
|
||||
return math.round(Ineger * Multiplier) / Multiplier
|
||||
end
|
||||
|
||||
local function MegabitToGigabit(Megabit: number): number
|
||||
return Megabit / 1000
|
||||
end
|
||||
|
||||
print(`-- FINISHED --`)
|
||||
print(`Response packet size: {SizeInMiB} MiB`)
|
||||
print(`Time elapsed: {Round(TimeTook, 3)}`)
|
||||
print(`Number of unsuccessful requests: {NumRequests - Successful}`)
|
||||
print(`Success %: {math.round((Successful / NumRequests) * 100)}%`)
|
||||
print(`Requests/second: {math.round(NumRequests / TimeTook)}`)
|
||||
print(`Bandwidth/second: {Round(MegabitToGigabit(NumRequests * SizeInMiB), 3)} GBit`)
|
||||
print(`Average response time: {Round((TimeTook / NumRequests) * 1000, 3)}ms`)
|
||||
|
||||
Server:disconnect()
|
Reference in New Issue
Block a user