Skip to content

Instantly share code, notes, and snippets.

@fidelisrafael
Created July 12, 2016 11:20
Show Gist options
  • Save fidelisrafael/92b6a0fe77078396339eaa5c19ccb46c to your computer and use it in GitHub Desktop.
Save fidelisrafael/92b6a0fe77078396339eaa5c19ccb46c to your computer and use it in GitHub Desktop.
-- base64 lib code: https://github.com/ErnieE5/ee5_base64
base64 = require("base64lib")
local str_size = 1000000
local tries = 100
local plain_string, encoded_string = '', ''
local function print_results(size, from_time)
print(string.format('%s, %s', size, (os.clock() - from_time)))
end
-- trying to use '..' operator inside a loop is a huge stupid choice
-- http://stackoverflow.com/a/19139394/1057087
local buf = {}
for i=0,str_size do buf[#buf+1] = 'a' end
plain_string = table.concat(buf)
print("encode: ")
local s,t = 0, os.clock()
for i=0,tries,1 do
encoded_string = base64.encode(plain_string)
s = s + string.len(encoded_string)
end
print_results(s, t)
print("decode: ")
local s,t = 0, os.clock()
for i=0,tries,1
do
local str3 = base64.decode(encoded_string)
s = s + string.len(str3)
end
print_results(s, t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment