Performance Tool(7)Improve Lua and Wrk
Basic Lua Language
On intellij, we have the lua plugins. So we need to run the hello.lua as follow:
[Edit the Configuration] ——> [Lua Interpreter] —> /usr/local/bin/lua ——> [Working Directory] —> /Users/carl/work/easy/easylua/src/main/lua
It is great to have Lua Scripts.
Script to do base64, base64.lua I get it from github.
-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de>
-- licensed under the terms of the LGPL2
-- character table string
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- encoding
function enc(data)
return ((data:gsub('.', function(x)
local r,b='',x:byte()
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
return r;
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c=0
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
return b:sub(c+1,c+1)
end)..({ '', '==', '=' })[#data%3+1])
end
-- decoding
function dec(data)
data = string.gsub(data, '[^'..b..'=]', '')
return (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(7-i) or 0) end
return string.char(c)
end))
end
return {
dec = dec,
enc = enc
}
The fileutil.lua, I take some references and write it follow the pattern
--
-- Created by IntelliJ IDEA.
-- User: carl
-- Date: 1/16/15
-- Time: 3:10 PM
-- To change this template use File | Settings | File Templates.
--
-- Opens a file in read
function appendResult(filename,append)
-- Opens a file in append mode
file = io.open(filename, "a")
-- sets the default output file as test.lua
io.output(file)
-- appends a word test to the last line of the file
io.write(append .. '\n')
-- closes the open file
io.close(file)
end
return {
appendResult = appendResult
}
datetimeutil.lua, I google and find it as references:
function format_time(timestamp, format, tzoffset, tzname)
if tzoffset == "local" then -- calculate local time zone (for the server)
local now = os.time()
local local_t = os.date("*t", now)
local utc_t = os.date("!*t", now)
local delta = (local_t.hour - utc_t.hour)*60 + (local_t.min - utc_t.min)
local h, m = math.modf( delta / 60)
tzoffset = string.format("%+.4d", 100 * h + 60 * m)
end
tzoffset = tzoffset or "GMT"
format = format:gsub("%%z", tzname or tzoffset)
if tzoffset == "GMT" then
tzoffset = "+0000"
end
tzoffset = tzoffset:gsub(":", "")
local sign = 1
if tzoffset:sub(1,1) == "-" then
sign = -1
tzoffset = tzoffset:sub(2)
elseif tzoffset:sub(1,1) == "+" then
tzoffset = tzoffset:sub(2)
end
tzoffset = sign * (tonumber(tzoffset:sub(1,2))*60 +
tonumber(tzoffset:sub(3,4)))*60
return os.date(format, timestamp + tzoffset)
end
return {
format_time = format_time
}
urlencode.lua class
function urlencode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([*+@/{\":,])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, "(})",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
sha2.lua
--
-- Le SHA2 Library
--
local bit = require("libbit");
--- Round constants
-- computed as the fractional parts of the cuberoots of the first 64 primes
local k256 = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
}
--- Preprocess input message
local function preprocess256(input)
local length = #input; -- length in bits
local padding = 64 - ((length + 9) % 64);
input = input .. "\128" .. ("\0"):rep(padding) .. "\0\0\0\0" ..
bit.int32_str(length*8);
return input;
end
--- Process an individual block using SHA256
-- Note: Lua arrays start at 1, not 0.
-- This behavior is respected in loop counters.
--
--@param `input` is the original input message
--@param `t` is the position of the first byte of this block
--@param `H` is the internal hash state
local function digest_block256(input, t, H)
local s10; -- Using 1 var for s0,s1 to help LuaJIT register alloc
local t1, t2;
local chmaj; -- May be used in place of s0
local word;
local a, b, c, d, e, f, g, h;
local k = k256;
local band, bnot, bxor, ror = bit.band, bit.bnot, bit.bxor, bit.ror
local rshift = bit.rshift;
local limit = 2^32;
local W = {};
local int32 = bit.str_int32;
local chunk;
local c1 = 0; -- #W, #words
chunk = input:sub(t, t + 63);
c1 = 0;
for i = 1, 64, 4 do
c1 = c1 + 1;
W[c1] = int32(chunk:sub(i, i+3));
end
-- Extend 16 words into 64
for t = 17, 64 do
word = W[t - 2];
s10 = bxor(ror(word, 17), ror(word, 19), rshift(word, 10));
word = W[t - 15];
chmaj = bxor(ror(word, 7), ror(word, 18), rshift(word, 3));
W[t] = s10 + W[t - 7] + chmaj + W[t - 16];
end
a, b, c, d = H[1], H[2], H[3], H[4];
e, f, g, h = H[5], H[6], H[7], H[8];
for t = 1, 64 do
s10 = bxor(ror(e, 6), ror(e, 11), ror(e, 25));
chmaj = bxor(band(e, f), band(bnot(e), g));
t1 = h + s10 + chmaj + k[t] + W[t];
s10 = bxor(ror(a, 2), ror(a, 13), ror(a, 22));
chmaj = bxor(band(a, b), band(a, c), band(b, c));
t2 = s10 + chmaj;
h = g;
g = f;
f = e;
e = d + t1;
d = c;
c = b;
b = a;
a = t1 + t2;
end
H[1] = (a + H[1]) % limit;
H[2] = (b + H[2]) % limit;
H[3] = (c + H[3]) % limit;
H[4] = (d + H[4]) % limit;
H[5] = (e + H[5]) % limit;
H[6] = (f + H[6]) % limit;
H[7] = (g + H[7]) % limit;
H[8] = (h + H[8]) % limit;
end
--- Calculate the SHA224 digest of a message
-- Note: sha224() does not use variable names complaint with FIPS 180-2
--@param `input` the message
local function sha224(input)
local output = "";
local state;
input = preprocess256(input);
state = {
0xc1059ed8,
0x367cd507,
0x3070dd17,
0xf70e5939,
0xffc00b31,
0x68581511,
0x64f98fa7,
0xbefa4fa4,
};
for i = 1, #input, 64 do
digest_block256(input, i, state);
end
for i = 1, 7 do
output = ("%s%08x"):format(output, state[i]);
end
return output;
end
--- Calculate the SHA256 digest of a message
-- Note: sha256() does not use variable names complaint with FIPS 180-2
--@param `input` the message
local function sha256(input)
local output = "";
local state;
input = preprocess256(input);
state = {
0x6a09e667,
0xbb67ae85,
0x3c6ef372,
0xa54ff53a,
0x510e527f,
0x9b05688c,
0x1f83d9ab,
0x5be0cd19,
};
for i = 1, #input, 64 do
digest_block256(input, i, state);
end
for i = 1, 8 do
output = ("%s%08x"):format(output, state[i]);
end
return output;
end
return {
sha224 = sha224;
sha256 = sha256;
}
I will have all the files in perf.
References:
相关推荐
标题“lua and acl example”揭示了本主题是关于使用Lua脚本语言与Access Control Lists (ACL)相结合的一个示例。Lua是一种轻量级的、解释型的编程语言,常用于游戏开发、配置文件、服务器应用等领域。而ACL则通常...
"Lua Performance Tips"这份文档深入探讨了如何通过遵循一些编程准则和技巧来提升Lua程序的执行效率。以下是对这些要点的详细解析: 1. **理解Table的运作机制** Lua中的Table是其核心数据结构,用于实现数组、...
4. **Lua脚本**:wrk支持自定义Lua脚本,允许用户控制请求的生成、处理响应和统计结果,增加了测试的灵活性。 ### wrk在不同Linux环境中的应用 1. **CentOS 7**:CentOS是一个基于RHEL的稳定版操作系统,广泛应用...
本示例探讨了如何在Delphi 7环境中实现与Lua脚本语言的相互调用,这在游戏开发、自动化工具或扩展应用程序功能时非常有用。Delphi是Pascal语言的一个强大的IDE,而Lua则是一种轻量级的脚本语言,以其简洁和可嵌入性...
Windows7 下 Lua 的编译和配置使用 Visual Studio 在学习 Cocos2d-x 的开发技术中,需要编译 Lua,以下是 Windows7 下使用 Visual Studio 编译和配置 Lua 的详细步骤。 一、环境配置 * 操作系统:Windows 7 64 位...
wrk允许用户编写Lua脚本,以执行更复杂的测试任务,如POST请求、设置自定义头、处理响应等。以下是一个简单的Lua脚本示例,用于发送POST请求: ```lua function request() return { method = "POST", path = "/...
obs-文本-脚本 date-and-time.lua
Game Programming with Python Lua And Ruby
1. **下载源码**:首先,你需要从wrk的官方GitHub仓库或者通过给定的7z压缩文件下载wrk-4.1.0的源代码。由于文件较大,可能需要使用7-Zip进行解压,然后将解压后的文件转换为.tar格式,以便于在Linux系统上传输和...
LUAC脚本是一种基于Lua语言的编译格式,它将Lua源代码编译成字节码,以便在 Lua 解释器上高效运行。LUAC(Lua Compiler)是Lua官方提供的编译器,它将源代码转换为这种优化的字节码,以提高执行速度。在游戏开发、...
所有版本LUA源码 lua-5.3.5 lua-5.3.4 lua-5.3.3 lua-5.3.2 lua-5.3.1 lua-5.3.0 lua-5.2.4 lua-5.2.3 lua-5.2.2 lua-5.2.1 lua-5.2.0 lua-5.1.5 lua-5.1.4 lua-5.1.3 lua-5.1.2 lua-5.1.1 lua-5.1 lua-5.0.3 lua-...
Lua源代码是文本形式的,易于阅读和编写,但为了保护代码不被轻易篡改或盗用,开发者通常会将Lua代码编译成字节码(.lua.c文件或.luac文件)。"LUAC"就是Lua的官方编译器,它将Lua源代码转换为字节码,以提高执行...
a utf-8 support module for Lua and LuaJIT 源码地址:https://github.com/starwing/luautf8 编译后可用的库: Linux版:lua-utf8.so Windows版:lua-utf8.dll(若是用在openresty中,openresty版本需使用32位版本...
《Lua在Nginx中的应用:Lua-Nginx-Module 0.10.9rc7详解》 Lua-Nginx-Module是Nginx服务器中一个强大的扩展模块,允许我们在Nginx配置文件中直接嵌入Lua脚本,极大地提高了Nginx处理动态请求的能力。本文将详细探讨...
"LUAC解密工具"就是针对Lua编译后的二进制文件(.luac)进行解密的工具,目的是为了让加密过的Lua代码能够恢复成可读的源代码格式(.lua)。 LUAC是Lua的编译器,它将Lua源代码转换为字节码,这个过程通常是为了...
《用Python,Lua和Ruby语言设计游戏-Game.Programming.with.Python.Lua.And.Ruby》这本书深入探讨了如何利用这些语言的优势来构建游戏。 Python在游戏开发中的应用主要体现在其强大的库支持和清晰的语法结构上。例如...