diff options
author | chai <chaifix@163.com> | 2021-10-20 19:36:15 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-20 19:36:15 +0800 |
commit | f2dcd16fc72e2f10c9504897bacf5c4c2ecff516 (patch) | |
tree | 29cb7704db0e75bb16b31c1541abcf871f623cd8 /Resources/DefaultContent/Libraries/lbase64/bench.lua | |
parent | afdcbfa9c4259fb003fd072ae011836230e7e39b (diff) |
+lua libs
Diffstat (limited to 'Resources/DefaultContent/Libraries/lbase64/bench.lua')
-rw-r--r-- | Resources/DefaultContent/Libraries/lbase64/bench.lua | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Resources/DefaultContent/Libraries/lbase64/bench.lua b/Resources/DefaultContent/Libraries/lbase64/bench.lua new file mode 100644 index 0000000..d24c1bf --- /dev/null +++ b/Resources/DefaultContent/Libraries/lbase64/bench.lua @@ -0,0 +1,76 @@ +local base64 = require'base64' +local N = 10000000 +local st = {} +local letters = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' + .. 'абвгдеёжзийклмнопрстуфхцшщчъыьэюя' + .. 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦШЩЧЪЫЬЭЮЯ' +local nletters = #letters +for i = 1, N do + local j = math.random( nletters ) + st[i] = letters:sub( j, j ) +end +local s = table.concat( st ) +local t = os.clock() +local encoded = base64.encode( s ) +local encodetime = os.clock() - t + +t = os.clock() +local decoded = base64.decode( encoded ) +local decodetime = os.clock() - t + +assert( s == decoded ) +print('Common text') +print(('Encoding: %d bytes/sec'):format( math.floor(N/encodetime))) +print(('Decoding: %d bytes/sec'):format( math.floor(N/decodetime))) +collectgarbage() + +t = os.clock() +encoded = base64.encode( s, nil, true ) +encodetime = os.clock() - t + +t = os.clock() +decoded = base64.decode( encoded, nil, true ) +assert( s == decoded ) +decodetime = os.clock() - t +print('Common text (cache)') +print(('Encoding: %d bytes/sec'):format( math.floor(N/encodetime))) +print(('Decoding: %d bytes/sec'):format( math.floor(N/decodetime))) +collectgarbage() + +local lt = {} +for i = 0, 255 do + lt[i] = string.char(i) +end +nletters = #lt +for i = 1, N do + local j = math.random( nletters ) + st[i] = lt[j] +end +s = table.concat( st ) + +t = os.clock() +encoded = base64.encode( s, nil ) +encodetime = os.clock() - t + +t = os.clock() +decoded = base64.decode( encoded ) +decodetime = os.clock() - t + +assert( s == decoded ) +print('Binary') +print(('Encoding: %d bytes/sec'):format( math.floor(N/encodetime))) +print(('Decoding: %d bytes/sec'):format( math.floor(N/decodetime))) +collectgarbage() + +t = os.clock() +encoded = base64.encode( s, nil, true ) +encodetime = os.clock() - t + +t = os.clock() +decoded = base64.decode( encoded, nil, true ) +assert( s == decoded ) +decodetime = os.clock() - t +print('Binary (cache)') +print(('Encoding: %d bytes/sec'):format( math.floor(N/encodetime))) +print(('Decoding: %d bytes/sec'):format( math.floor(N/decodetime))) +collectgarbage() |