thibaultcha / lua-resty-jit-uuid

Fast and dependency-free UUID library for LuaJIT/ngx_lua
http://thibaultcha.github.io/lua-resty-jit-uuid/
MIT License
206 stars 40 forks source link

Performance comparision #5

Closed rohitjoshi closed 8 years ago

rohitjoshi commented 8 years ago

Performance comparing jit vs ffi seem to be much larger.

JIT:

time /opt/capione/bin/resty -I '/opt/openresty/nginx/lualib'  -e 'local u = require("resty.jit-uuid") u.seed() for i=1, 10000000 do local uuid_str = u() end'

real    0m7.874s
user    0m7.837s
sys 0m0.023s

FFI:

time /opt/capione/bin/resty -I '/opt/openresty/nginx/lualib'  -e 'local u = require("resty.ffi-uuid") u.seed() for i=1, 10000000 do local uuid_str = u() end'

real    0m1.009s
user    0m0.983s
sys 0m0.019s
thibaultcha commented 8 years ago

For sure the FFI is much, much faster (I don't think benchmarking at 10^7 is very realistic, and it takes so much time with Lua/LuaJIT it makes it harder to iterate).

In both cases (10^6and 10^7) you can find out that the FFI is more performant by about 85/90%. So I fail to see how the difference is larger with 10^7. The thing to keep in mind is that yes, the FFI completely crushes any other implementation, as expected :D

Feel free to suggest performance improvements.

thibaultcha commented 8 years ago

Hey,

As an attempt to reduce future confusion, I just added a field to the benchmark results to compare the % difference between existing solutions:

UUID generation (1e+06 UUIDs)
1. FFI binding took: 0.095588s -86%
2. C binding   took: 0.234322s -66%
3. Pure LuaJIT took: 0.703376s +0%
4. Pure Lua    took: 1.908608s +171%

Those are the same results as the ones you reported. As of today, I don't think LuaJIT can perform better for UUID v4 (unless I am missing some optimizations).

Also, feel free to use the provided bench.lua benchmarks (you can edit the number of UUIDs and dataset to play with).

thibaultcha commented 8 years ago

Hey @rohitjoshi,

Good news: we are now more performant than even the FFI binding itself ;)

Enjoy

rohitjoshi commented 8 years ago

@thibaultCha thanks for the update.