Base64
Base64 copied to clipboard
Improve performance.
This version runs significantly better (it's the older version of the library with a few tweaks).
local Base64 = require(script.Base64)
local HmsBase64 = require(script.HmsBase64)
local function BenchmarkFunction(Library)
return function(Profiler, String)
Profiler.Begin("Encode")
local New = Library.encode(String)
Profiler.End()
Profiler.Begin("Decode")
local _ = Library.decode(New)
Profiler.End()
end
end
local CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+[{]}\\|;:'\"<,>./?"
local RandomLib = Random.new(os.clock() % 1 * 1E7)
local LENGTH = 1000
local function RandomString()
local String = table.create(LENGTH)
local Length = 0
for _ = LENGTH, 0, -1 do
local Index = math.floor(RandomLib:NextNumber() * 94)
Length += 1
String[Length] = string.sub(CHARACTERS, Index, Index)
end
return table.concat(String)
end
local String = RandomString()
assert(Base64.encode(String) == HmsBase64.encode(String))
return {
ParameterGenerator = RandomString;
Functions = {
["HmsBase64"] = BenchmarkFunction(HmsBase64);
["Base64"] = BenchmarkFunction(Base64);
};
}
This code nets the following result:

This needs to be tested with different input sizes. I found the latest version was up to 10x faster when I tested it on large payloads (1mb+).
I got the opposite with a payload of about 1mb.
As well as 3.3mb.
Here's the code in zip file. Base64.zip