Revisions for ⁨Garbage⁩

View the changes made to this paste.

unlisted ⁨1⁩ ⁨file⁩ 2021-11-08 03:47:53 UTC

pastefile1

@@ -0,0 +1,133 @@

+CONTAINER =
+{
+  Ver = "0.3",
+  --- integer lookup for the DateTime
+  timeLUT = {[0]="00",[1]="01",[2]="02",[3]="03",[4]="04",[5]="05",[6]="06",[7]="07",[8]="08",[9]="09"},
+  strCACHE = { [100] = ""},
+  SubStrA = "Unknown",
+  SubAPrst = "ASjdasda",
+}
+
+for i = 10,99,1 do
+  CONTAINER.timeLUT[i] = tostring(i)
+end
+
+
+DataBlob = {
+  vAng = { x = 1.0, y = 2.0, z = 3.0},
+  vPos = { x = 2131.0, y = 42.0, z = -433.0},
+  Composite =
+  {
+    VARIANT1 = { isFirst = true, isMiddle = false, isLast = true },
+    VARIANT2 = { isIgnored = true},
+    VARIANT3 = { isAccurate = false },
+    VARIANT4 = { bEnabled = false },
+    VARIANT5 = { isLocked = false, ImpactV = 1.8 },
+    VARIANT6 = { troCoWal = true },
+    VARIANT7 = { isBroCal = false }
+  }
+}
+
+Global = {
+
+  isLocked = function(x)return false end,
+  GetTimeStamp = function(x)return math.random() + math.random(1, 99) end,
+  GetLocalTimeStamp = function(x)return math.random() + math.random(1, 99) end,
+  GetTotalPTime = function(x)return math.random() + math.random(1, 99) end,
+  GetDataBlob = function(x)return DataBlob end,
+  GetName = function(x)return "AThing" end
+}
+
+
+function CONTAINER.PopulateState()
+
+  -- GC first
+  local gcInit = collectgarbage("count")
+  -- Cachig globals
+  local floor, mod, tostring = math.floor, math.mod, tostring
+  local G = Global
+  local intCache = CONTAINER.timeLUT
+  local strBuilder = CONTAINER.strCACHE
+  -- Fetching & caching data
+  local locDB, Name = G.GetDataBlob(), G.GetName()
+  local ts = G.GetTimeStamp()
+  local lag = math.random() + math.random(1, 2)
+
+  -- Local helpers
+  local function sBool(bool)
+     return bool and "1" or "0"
+  end
+  local t = 0
+
+  function cAppend(cTbl, ...)
+  for i=0, arg.n do
+    cTbl[#cTbl+1] = arg[i]
+    t = t +1
+    end
+  end
+
+  function cClear(cTbl)
+    for _=0, #cTbl do
+      cTbl[#cTbl] = nil
+    end
+end
+
+  -- Populating table
+  cClear(strBuilder)
+
+  if locDB ~= nil then
+    locDB = G.GetDataBlob()
+    local PC = locDB.Composite
+    local tp = G.GetTotalPTime()
+    local d, h, m, s = floor(tp/86400), floor(mod(tp, 86400)/3600), floor(mod(tp,3600)/60), floor(mod(tp,60))
+
+    cAppend(strBuilder,  "[", Name, "]:\n",
+                         "Ang :",      "(", tostring(locDB.vAng.x),",",tostring(locDB.vAng.y),",",tostring(locDB.vAng.z), ")\n",
+                         "Pos :",      "(", tostring(locDB.vPos.x),",",tostring(locDB.vPos.y),",",tostring(locDB.vPos.z), ")\n",
+                         "isLocked: ", sBool(G.isLocked()),  "\n")
+
+    if (locDB.Composite["VARIANT1"] ~= nil) then
+      cAppend(strBuilder, "isFirst / isLast: ", sBool(PC.VARIANT1.isFirst)," / ",sBool(PC.VARIANT1.isLast), "\n",
+                          "isMiddle: ",         sBool(PC.VARIANT1.isMiddle), "\n")
+    end
+    if (locDB.Composite["VARIANT2"] ~= nil) then
+      cAppend(strBuilder, "isIgnored: ",  sBool(PC.VARIANT2.isIgnored),  "\n")
+    end
+    if (locDB.Composite["VARIANT4"] ~= nil) then
+      cAppend(strBuilder, "bEnabled: ",   sBool(PC.VARIANT4.bEnabled),   "\n")
+    end
+    if (locDB.Composite["VARIANT3"] ~= nil) then
+      cAppend(strBuilder, "isAccurate: ", sBool(PC.VARIANT3.isAccurate), "\n")
+    end
+    if (locDB.Composite["VARIANT5"] ~= nil) then
+      cAppend(strBuilder, "isLocked: ",   sBool(PC.VARIANT5.isLocked),   "\n",
+                          "ImpactV: ",    tostring(PC.VARIANT5.ImpactV), "\n")
+    end
+    if (locDB.Composite["VARIANT6"]) then
+      cAppend(strBuilder, "troCoWal: ",   sBool(PC.VARIANT6.troCoWal),   "\n")
+    end
+    if (locDB.Composite["VARIANT7"]) then
+      cAppend(strBuilder, "isBroCal: ",   sBool(PC.VARIANT7.isBroCal),   "\n")
+    end
+
+    local gcLast = collectgarbage("count")
+
+    cAppend(strBuilder, "Time taken: ",intCache[d],":",intCache[h],":",intCache[m],":",intCache[s], "\n",
+                        "TS: ",        tostring(ts),                   "\n",
+                        "local TS: ",  tostring(G.GetLocalTimeStamp()),"\n",
+                        "Lag: ",       string.format("%.5f", lag) , " ms\n",
+                        "Heap: ",      tostring(gcLast),             "KB\n")
+
+    cAppend(strBuilder, "Alloc: ",     tostring(gcLast-gcInit),"KB"," (v", CONTAINER.Ver, ")","\n",
+                        "Extra: ",     CONTAINER.SubStrA, "_", CONTAINER.SubAPrst,             "\n")
+  
+  print("Allocated pre-concat: " ..  tostring(gcLast-gcInit))
+  end
+  collectgarbage("collect")
+  table.concat(strBuilder)
+  print("Allocated post-concat: " ..  tostring(collectgarbage("count")))
+  print("Total table metabytes: " .. tostring(t*16))
+end
+
+collectgarbage("collect") 
+CONTAINER.PopulateState()
\ No newline at end of file