forked from supermy/mytools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nginx 缓存webjars 配置;
- Loading branch information
Showing
33 changed files
with
766 additions
and
34 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
local template = require "resty.template" | ||
local escape = template.escape | ||
local concat = table.concat | ||
local pairs = pairs | ||
local type = type | ||
|
||
local function tag(name, content, attr) | ||
local r, a, content = {}, {}, content or attr | ||
r[#r + 1] = "<" | ||
r[#r + 1] = name | ||
if attr then | ||
for k, v in pairs(attr) do | ||
if type(k) == "number" then | ||
a[#a + 1] = escape(v) | ||
else | ||
a[#a + 1] = k .. '="' .. escape(v) .. '"' | ||
end | ||
end | ||
if #a > 0 then | ||
r[#r + 1] = " " | ||
r[#r + 1] = concat(a, " ") | ||
end | ||
end | ||
if type(content) == "string" then | ||
r[#r + 1] = ">" | ||
r[#r + 1] = escape(content) | ||
r[#r + 1] = "</" | ||
r[#r + 1] = name | ||
r[#r + 1] = ">" | ||
else | ||
r[#r + 1] = " />" | ||
end | ||
return concat(r) | ||
end | ||
|
||
local html = { __index = function(_, name) | ||
return function(attr) | ||
if type(attr) == "table" then | ||
return function(content) | ||
return tag(name, content, attr) | ||
end | ||
else | ||
return tag(name, attr) | ||
end | ||
end | ||
end } | ||
|
||
template.html = setmetatable(html, html) | ||
|
||
return template.html |
121 changes: 121 additions & 0 deletions
121
web+app/mynginx/nginx.d/lua/resty/html/microbenchmark.lua
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
local template = require "resty.template" | ||
|
||
local ok, new_tab = pcall(require, "table.new") | ||
if not ok then | ||
new_tab = function (narr, nrec) return {} end | ||
end | ||
|
||
local function run(iterations) | ||
local total, print, parse, compile, iterations, clock = 0, ngx and ngx.say or print, template.parse, template.compile, iterations or 1000, os.clock | ||
|
||
local view = [[ | ||
<ul> | ||
{% for _, v in ipairs(context) do %} | ||
<li>{{v}}</li> | ||
{% end %} | ||
</ul>]] | ||
|
||
print(string.format("Running %d iterations in each test", iterations)) | ||
|
||
local x = clock() | ||
for i = 1, iterations do | ||
parse(view, true) | ||
end | ||
local z = clock() - x | ||
print(string.format(" Parsing Time: %.6f", z)) | ||
total = total + z | ||
|
||
x = clock() | ||
for i = 1, iterations do | ||
compile(view, nil, true) | ||
template.cache = {} | ||
end | ||
z = clock() - x | ||
print(string.format("Compilation Time: %.6f (template)", z)) | ||
total = total + z | ||
|
||
compile(view, nil, true) | ||
|
||
x = clock() | ||
for i = 1, iterations do | ||
compile(view, 1, true) | ||
end | ||
z = clock() - x | ||
print(string.format("Compilation Time: %.6f (template cached)", z)) | ||
total = total + z | ||
|
||
local context = { "Emma", "James", "Nicholas", "Mary" } | ||
|
||
template.cache = {} | ||
|
||
x = clock() | ||
for i = 1, iterations do | ||
compile(view, 1, true)(context) | ||
template.cache = {} | ||
end | ||
z = clock() - x | ||
print(string.format(" Execution Time: %.6f (same template)", z)) | ||
total = total + z | ||
|
||
template.cache = {} | ||
compile(view, 1, true) | ||
|
||
x = clock() | ||
for i = 1, iterations do | ||
compile(view, 1, true)(context) | ||
end | ||
z = clock() - x | ||
print(string.format(" Execution Time: %.6f (same template cached)", z)) | ||
total = total + z | ||
|
||
template.cache = {} | ||
|
||
local views = new_tab(iterations, 0) | ||
for i = 1, iterations do | ||
views[i] = "<h1>Iteration " .. i .. "</h1>\n" .. view | ||
end | ||
|
||
x = clock() | ||
for i = 1, iterations do | ||
compile(views[i], i, true)(context) | ||
end | ||
z = clock() - x | ||
print(string.format(" Execution Time: %.6f (different template)", z)) | ||
total = total + z | ||
|
||
x = clock() | ||
for i = 1, iterations do | ||
compile(views[i], i, true)(context) | ||
end | ||
z = clock() - x | ||
print(string.format(" Execution Time: %.6f (different template cached)", z)) | ||
total = total + z | ||
|
||
template.cache = {} | ||
local contexts = new_tab(iterations, 0) | ||
|
||
for i = 1, iterations do | ||
contexts[i] = {"Emma " .. i, "James " .. i, "Nicholas " .. i, "Mary " .. i } | ||
end | ||
|
||
x = clock() | ||
for i = 1, iterations do | ||
compile(views[i], i, true)(contexts[i]) | ||
end | ||
z = clock() - x | ||
print(string.format(" Execution Time: %.6f (different template, different context)", z)) | ||
total = total + z | ||
|
||
x = clock() | ||
for i = 1, iterations do | ||
compile(views[i], i, true)(contexts[i]) | ||
end | ||
z = clock() - x | ||
print(string.format(" Execution Time: %.6f (different template, different context cached)", z)) | ||
total = total + z | ||
print(string.format(" Total Time: %.6f", total)) | ||
end | ||
|
||
return { | ||
run = run | ||
} |
Oops, something went wrong.