Skip to content

Instantly share code, notes, and snippets.

@Validark
Created June 21, 2020 12:33
Show Gist options
  • Select an option

  • Save Validark/03278a567ef331676259b5d259a10ecf to your computer and use it in GitHub Desktop.

Select an option

Save Validark/03278a567ef331676259b5d259a10ecf to your computer and use it in GitHub Desktop.
Roblox Studio grapher.lua
-- ugh.lua
local function foo1(...)
local result = {}
for i = 1, select("#", ...) do
result[i] = (select(i, ...)) .. "b"
end
return result
end
local function foo2(...)
local args = { ... }
local result = {}
for i, v in ipairs(args) do
result[i] = v .. "b"
end
return result
end
local Functions = {
{
callback = foo1,
color = Color3.fromRGB(255, 0, 0)
},
{
callback = foo2,
color = Color3.fromRGB(0, 0, 255)
},
}
game:GetService("StarterGui"):ClearAllChildren()
local SpeedTestScreen = Instance.new("ScreenGui")
SpeedTestScreen.DisplayOrder = 2147483647
SpeedTestScreen.Name = "SpeedTestScreen"
SpeedTestScreen.Parent = game:GetService("StarterGui")
local Backdrop = Instance.new("Frame")
Backdrop.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Backdrop.Name = "Backdrop"
Backdrop.Size = UDim2.new(1, 0, 1, 0)
Backdrop.Parent = SpeedTestScreen
local YAxis = Instance.new("Frame")
YAxis.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
YAxis.BorderSizePixel = 0
YAxis.Position = UDim2.new(0, 100, 0, 80)
YAxis.Size = UDim2.new(0, 3, 0, 523)
YAxis.ZIndex = 2
YAxis.Parent = Backdrop
local XAxis = Instance.new("Frame")
XAxis.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
XAxis.BorderSizePixel = 0
XAxis.Position = UDim2.new(0, 100, 0, 600)
XAxis.Size = UDim2.new(0, 1200, 0, 3)
XAxis.ZIndex = 2
XAxis.Parent = Backdrop
do
local XAxisLabel = Instance.new("TextLabel")
XAxisLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
XAxisLabel.BackgroundTransparency = 1
XAxisLabel.Font = Enum.Font.SourceSans
XAxisLabel.Position = UDim2.new(0, 700, 0, 640)
XAxisLabel.Text = "Number of Arguments"
XAxisLabel.TextColor3 = Color3.fromRGB(0, 0, 0)
XAxisLabel.TextSize = 36
XAxisLabel.Parent = Backdrop
local YAxisLabel = Instance.new("TextLabel")
YAxisLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
YAxisLabel.BackgroundTransparency = 1
YAxisLabel.Font = Enum.Font.SourceSans
YAxisLabel.Position = UDim2.new(0, 30, 0, 310)
YAxisLabel.Rotation = -90
YAxisLabel.Text = "Avg execution time (seconds)"
YAxisLabel.TextColor3 = Color3.fromRGB(0, 0, 0)
YAxisLabel.TextSize = 36
YAxisLabel.Parent = Backdrop
local GraphTitle = Instance.new("TextLabel")
GraphTitle.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
GraphTitle.BackgroundTransparency = 1
GraphTitle.Font = Enum.Font.SourceSans
GraphTitle.Position = UDim2.new(0, 700, 0, 40)
GraphTitle.Text = "Number of Arguments vs Average execution time"
GraphTitle.TextColor3 = Color3.fromRGB(0, 0, 0)
GraphTitle.TextSize = 36
GraphTitle.Parent = Backdrop
end
local Runs = Instance.new("TextLabel")
Runs.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Runs.BackgroundTransparency = 1
Runs.Font = Enum.Font.SourceSans
Runs.Position = UDim2.new(0, 1400, 0, 320)
Runs.Text = "Runs: 0"
Runs.TextColor3 = Color3.fromRGB(0, 0, 0)
Runs.TextSize = 24
Runs.Visible = false
Runs.Parent = Backdrop
do
local YAxisListLayout = Instance.new("UIListLayout")
YAxisListLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
YAxisListLayout.Padding = UDim.new(0, 2)
YAxisListLayout.SortOrder = Enum.SortOrder.LayoutOrder
YAxisListLayout.VerticalAlignment = Enum.VerticalAlignment.Bottom
YAxisListLayout.Parent = YAxis
local XAxisListLayout = Instance.new("UIListLayout")
XAxisListLayout.FillDirection = Enum.FillDirection.Horizontal
XAxisListLayout.Padding = UDim.new(0, 2)
XAxisListLayout.SortOrder = Enum.SortOrder.LayoutOrder
XAxisListLayout.VerticalAlignment = Enum.VerticalAlignment.Center
XAxisListLayout.Parent = XAxis
end
local TicMarkY = Instance.new("Frame")
TicMarkY.BackgroundColor3 = Color3.fromRGB(103, 103, 103)
TicMarkY.BorderSizePixel = 0
TicMarkY.Position = UDim2.new(0.5, 0, 0, -5)
TicMarkY.Size = UDim2.new(0, 7, 0, 2)
do
local TicMarkYLabel = Instance.new("TextLabel")
TicMarkYLabel.AnchorPoint = Vector2.new(0.5, 0.5)
TicMarkYLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
TicMarkYLabel.BackgroundTransparency = 1
TicMarkYLabel.Font = Enum.Font.SourceSans
TicMarkYLabel.Position = UDim2.new(0, -19, 0, 0)
TicMarkYLabel.TextColor3 = Color3.fromRGB(0, 0, 0)
TicMarkYLabel.TextSize = 14
TicMarkYLabel.Name = "label"
TicMarkYLabel.Text = ""
TicMarkYLabel.Parent = TicMarkY
end
local TicMarkX = Instance.new("Frame")
TicMarkX.BackgroundColor3 = Color3.fromRGB(103, 103, 103)
TicMarkX.BorderSizePixel = 0
TicMarkX.Position = UDim2.new(0.5, 0, 0, -5)
TicMarkX.Size = UDim2.new(0, 2, 0, 7)
do
local TicMarkXLabel = Instance.new("TextLabel")
TicMarkXLabel.AnchorPoint = Vector2.new(0.5, 0.5)
TicMarkXLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
TicMarkXLabel.BackgroundTransparency = 1
TicMarkXLabel.Font = Enum.Font.SourceSans
TicMarkXLabel.Position = UDim2.new(0, 1, 0, 14)
TicMarkXLabel.TextColor3 = Color3.fromRGB(0, 0, 0)
TicMarkXLabel.TextSize = 14
TicMarkXLabel.Name = "label"
TicMarkXLabel.Text = ""
TicMarkXLabel.Parent = TicMarkX
end
-- make X tic marks
local xmarks = {}
for i = 0, 300 do
local t = TicMarkX:Clone()
xmarks[i] = t
t.Name = i
if i % 10 == 0 then
t.label.Text = i
end
t.LayoutOrder = i
t.Parent = XAxis
end
-- make y tic marks
local function formatter(num)
return ("%.1fe-5"):format(num * 1e5)
end
local ymarks = {}
for i = 0, 130 do
-- 0.0e-6 to 1.0e-4
local k = i / 1e6
local c = formatter(k)
local t = TicMarkY:Clone()
ymarks[i] = t
t.Name = c
if i % 10 == 0 then
t.label.Text = c
end
t.LayoutOrder = 100 - i
t.Parent = YAxis
end
local function round(Number, Place, Threshold)
-- Rounds number to the nearest Place with a given Threshold towards ceiling
-- @param number Number the value to Round
-- @param number Place Number must be rounded to a multiple of Place
-- @default = 1
-- @param Threshold How biased it should be towards rounding up
-- @default = 0.5
-- When Threshold == 0, it Floors
-- When Threshold == 1, it Ceils
-- When Threshold == 0.5 (default), it Rounds to the nearest
Place = Place or 1
Number = Number + Place * (Threshold or 0.5)
return Number - Number % Place
end
local function getXPlacement(x)
return assert(xmarks[x]).AbsolutePosition.X
end
local function getYPlacement(y)
y = y * 1e6
local r = math.ceil(y) -- 12.15129838791237e-5 -> 122
local o = math.floor(y)
local y1 = assert(ymarks[r]).AbsolutePosition.Y
local y2 = assert(ymarks[o]).AbsolutePosition.Y
--print(y1, y2, y, math.max(y1, y2) - (math.abs(y1 - y2) * (y % 1)))
return (math.max(y1, y2) - (math.abs(y1 - y2) * (y % 1)))
end
-- Fairly retrieves a stack without having to unpack anything
local HoldStack do
local function StackHolder(...)
coroutine.yield()
while true do
coroutine.yield(...)
end
end
function HoldStack(...)
local co = coroutine.wrap(StackHolder)
co(...)
return co
end
end
local Point = Instance.new("Frame")
Point.BorderSizePixel = 0
Point.Size = UDim2.new(0, 2, 0, 2)
Point.AnchorPoint = Vector2.new(0.5, 0.5)
local function Plot(x, y, color)
--print(x, y)
local point = Point:Clone()
point.Position = UDim2.new(0, x, 0, y)
point.BackgroundColor3 = color
point.Parent = Backdrop
end
-- Did you know you can't unpack an array with 8000 entries or more? https://youtu.be/ZtuEbAzAess?t=58
for x = 0, 300 do
local getArgs = HoldStack(unpack(table.create(x, "")))
wait()
for _, f in ipairs(Functions) do
local callback = f.callback
local times = {}
local runs = 1e4
for i = 1, runs do
local t1 = tick()
callback(getArgs())
local t2 = tick() - t1
table.insert(times, t2)
end
table.sort(times)
local start = runs * 0.25
local finish = runs * 0.75
local avg = 0
for j = start, finish do
avg = avg + times[j]
end
local y = avg / (finish - start + 1)
--
--print(x, y)
Plot(getXPlacement(x), getYPlacement(y), f.color)
end
end
print("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment