Hi,
i encountered a strange problem while benchmarking some some supposedly trivial things of my code:
local find = string.find
local match = string.match
local tostring = tostring
local rep = string.rep
local floor = math.floor
local str = rep("b", 10000) .. "a"
local str2 = "ba"
local n = 5000000
local bench = function(n,desc,fun,arg)
ngx.update_time()
local start = ngx.now()
for i=1,n do
local tmp = fun(arg)
end
ngx.update_time()
local mu = tostring(floor((ngx.now() - start)*1000)/1000)
desc = desc .. ":"
ngx.say(desc,rep(" ",50-#desc),rep(" ",16-#mu),mu ,"s")
return 0
end
local function string_find(addr)
local t = find(addr,"a")
return t
end
local function string_match(addr)
local t = match(addr,"a")
return t
end
bench(n,"string_find",string_find,str)
bench(n,"string_match",string_match,str2)
when i execute this code in a location via content_by_lua_file, then i get the following results (case 1):
string_find: 0.002s
string_match: 0.684s
However, when i reverse the two bench functions by reversing the code lines (or reload the previous page with 'lua_code_cache on;') i get the following (case 2):
string_match: 0.632s
string_find: 2.416s
When using "jit.off()" i get:
string_find: 2.288s
string_match: 0.619s
Can anyone explain me, why in case 2 the string.find function is obviously not jit compiled anymore?
Specs: nginx/1.9.3 ngx_lua/0.9.16 archlinux/x64
$ nginx -V
nginx version: nginx/1.9.3
built by gcc 5.2.0 (GCC)
built with OpenSSL 1.0.2d 9 Jul 2015
TLS SNI support enabled
configure arguments: --prefix=/usr/local --conf-path=/etc/nginx/nginx.conf --error-log-path=/app/log/nginx.err --http-client-body-temp-path=/app/tmp/nginx/body --http-fastcgi-temp-path=/app/tmp/nginx/fastcgi --http-log-path=/app/log/nginx.acc --http-proxy-temp-path=/app/tmp/nginx/proxy --lock-path=/run/nginx/nginx.lock --pid-path=/run/nginx/nginx.pid --with-file-aio --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_geoip_module --with-http_mp4_module --with-ipv6 --with-pcre --with-pcre-jit --with-debug --without-http_charset_module --without-http_scgi_module --without-http_split_clients_module --without-http_ssi_module --without-http_userid_module --without-http_uwsgi_module --without-http_upstream_ip_hash_module --without-http_browser_module --without-http_memcached_module --without-http_geo_module --add-module=modules/ngx_devel_kit-0.2.19 --add-module=modules/lua-nginx-module-master --add-module=modules/headers-more-nginx-module-0.26 --add-module=modules/echo-nginx-module-0.58
Best regards