Skip to content

Commit

Permalink
Release 1.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
bungle committed Apr 25, 2016
1 parent 723d640 commit 7a95ca6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
3 changes: 1 addition & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

Changes with lua-resty-template 1.5 xx Xxx 2016
Changes with lua-resty-template 1.6 25 Apr 2016

*) Feature: Added short escaping syntax.

Expand Down
2 changes: 1 addition & 1 deletion lib/resty/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if not ok then newtab = function() return {} end end
local caching = true
local template = newtab(0, 12)

template._VERSION = "1.6-dev"
template._VERSION = "1.6"
template.cache = {}

local function enabled(val)
Expand Down
1 change: 1 addition & 0 deletions lib/resty/template/html.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local template = require "resty.template"
local setmetatable = setmetatable
local escape = template.escape
local concat = table.concat
local pairs = pairs
Expand Down
39 changes: 19 additions & 20 deletions lib/resty/template/microbenchmark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,69 @@ local template = require "resty.template"

local ok, new_tab = pcall(require, "table.new")
if not ok then
new_tab = function (narr, nrec) return {} end
new_tab = function() 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 total, print, parse, compile, iterations, clock, format = 0, ngx and ngx.say or print, template.parse, template.compile, iterations or 1000, os.clock, string.format
local view = [[
<ul>
{% for _, v in ipairs(context) do %}
<li>{{v}}</li>
{% end %}
</ul>]]

print(string.format("Running %d iterations in each test", iterations))
print(format("Running %d iterations in each test", iterations))

local x = clock()
for i = 1, iterations do
for _ = 1, iterations do
parse(view, true)
end
local z = clock() - x
print(string.format(" Parsing Time: %.6f", z))
print(format(" Parsing Time: %.6f", z))
total = total + z

x = clock()
for i = 1, iterations do
for _ = 1, iterations do
compile(view, nil, true)
template.cache = {}
end
z = clock() - x
print(string.format("Compilation Time: %.6f (template)", z))
print(format("Compilation Time: %.6f (template)", z))
total = total + z

compile(view, nil, true)

x = clock()
for i = 1, iterations do
for _ = 1, iterations do
compile(view, 1, true)
end
z = clock() - x
print(string.format("Compilation Time: %.6f (template cached)", z))
print(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
for _ = 1, iterations do
compile(view, 1, true)(context)
template.cache = {}
end
z = clock() - x
print(string.format(" Execution Time: %.6f (same template)", z))
print(format(" Execution Time: %.6f (same template)", z))
total = total + z

template.cache = {}
compile(view, 1, true)

x = clock()
for i = 1, iterations do
for _ = 1, iterations do
compile(view, 1, true)(context)
end
z = clock() - x
print(string.format(" Execution Time: %.6f (same template cached)", z))
print(format(" Execution Time: %.6f (same template cached)", z))
total = total + z

template.cache = {}
Expand All @@ -80,15 +79,15 @@ local function run(iterations)
compile(views[i], i, true)(context)
end
z = clock() - x
print(string.format(" Execution Time: %.6f (different template)", z))
print(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))
print(format(" Execution Time: %.6f (different template cached)", z))
total = total + z

template.cache = {}
Expand All @@ -103,17 +102,17 @@ local function run(iterations)
compile(views[i], i, true)(contexts[i])
end
z = clock() - x
print(string.format(" Execution Time: %.6f (different template, different context)", z))
print(format(" Execution Time: %.6f (different template, different context)", z))
total = total + z

x = clock()
for i = 1, iterations do
for i = 1, 1000 do
compile(views[i], i, true)(contexts[i])
end
z = clock() - x
print(string.format(" Execution Time: %.6f (different template, different context cached)", z))
print(format(" Execution Time: %.6f (different template, different context cached)", z))
total = total + z
print(string.format(" Total Time: %.6f", total))
print(format(" Total Time: %.6f", total))
end

return {
Expand Down

0 comments on commit 7a95ca6

Please sign in to comment.