forked from tarantool/tarantool
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a simple benchmark for URI escape/unescape. Part of tarantool#3682 NO_DOC=documentation is not required for performance test NO_CHANGELOG=performance test NO_TEST=performance test
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- It is recommended to run benchmark using taskset for stable results. | ||
-- taskset -c 1 tarantool uri_escape_unescape.lua | ||
|
||
local uri = require("uri") | ||
local clock = require("clock") | ||
local t = require("tarantool") | ||
|
||
local _, _, build_type = string.match(t.build.target, "^(.+)-(.+)-(.+)$") | ||
if build_type == "Debug" then | ||
print("WARNING: tarantool has built with enabled debug mode") | ||
end | ||
|
||
local escape_opts = { | ||
unreserved = uri.unreserved("A-Z"), | ||
plus = true, | ||
} | ||
-- Alternate reserved and unreserved symbols plus a space symbol. | ||
local str = "A$B$C$D$E$F$G$H$I$J$K$L$M$N$O$P$Q$R$S$T$U$V$W$X$Y$Z$ #" | ||
local encode_sample = string.rep(str, 10^3) | ||
local decode_sample = uri.escape(encode_sample, escape_opts) | ||
|
||
-- JIT compilation starts work after detecting "hot" paths in loops and | ||
-- function's calls. It potentially will make execution time of first | ||
-- iterations slower that next. To avoid such effect we can introduce | ||
-- "warmup" iterations, disable JIT at all or make JIT compilation | ||
-- aggressive from the beginning. | ||
jit.opt.start("hotloop=1", "hotexit=1", "recunroll=1", "callunroll=1") | ||
|
||
local cycles = 10^3 | ||
local start = clock.monotonic() | ||
for _ = 1, cycles do | ||
uri.escape(encode_sample) | ||
end | ||
local encode_time = cycles / (clock.monotonic() - start) | ||
|
||
start = clock.monotonic() | ||
for _ = 1, cycles do | ||
uri.unescape(decode_sample) | ||
end | ||
local decode_time = cycles / (clock.monotonic() - start) | ||
|
||
print(("uri.escape %.2f runs/sec"):format(encode_time)) | ||
print(("uri.unescape %.2f runs/sec"):format(decode_time)) |