-
-
Save fidelisrafael/92b6a0fe77078396339eaa5c19ccb46c to your computer and use it in GitHub Desktop.
Lua Base64 Benchmark - https://github.com/kostya/benchmarks/tree/master/base64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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