update oxmysql benchmark

This commit is contained in:
Linden committed 2023-07-12 15:43:56 +10:00
1 parent 7547b74dfa
commit 89fe600500
1 file changed
+56 -60
+56 -60
View File
@@ -1,73 +1,69 @@
# Benchmark # Benchmark
```lua Benchmarking is based on the time spent when to receive a response from exports.
-- Internal benchmark Real query speeds will be reported in the debug UI and in the server console.
Low: 0.1222ms | Avg: 0.14188357ms | Total: 1418.8357ms (10000 queries)
-- Round-trip-time for exports **Direct query**
Low: 0.1997ms | Avg: 0.25898800ms | Total: 2589.8800ms (10000 queries) - `SELECT username FROM test_table WHERE id = 68 LIMIT 1`
``` - Takes ~0.184ms
## Lua (5.4) **Export**
- `MySQL.query.await('SELECT username FROM test_table WHERE id = ? LIMIT 1', { 68 }`
- Takes ~1.956ms
Speeds will vary greatly based on system hardware, database settings, and the current workload.
>[ script:test] initialise test_table
>[ script:test] Executed 3 queries in 25.2018ms
>[ script:test] insert test users
>[ script:test] Executed 10000 queries in 2411.9601ms
>[ script:test] select every 4th userid
>[ script:test] Executed 2500 queries in 2891.9658ms
```lua ```lua
local val = 10000 CreateThread(function()
RegisterCommand('luasync', function() local function execQuery(fn, tbl, query)
local queryTimesLocal = {} local start = os.nanotime()
local result local result = fn(query or tbl, tbl)
MySQL.prepare.await('SELECT identifier from users WHERE lastname = ?', {'Linden'}) local finish = os.nanotime()
for i=1, val do print('Executed ' .. #tbl .. ' queries in ' .. (finish - start) / 1e6 .. 'ms')
local time = os.nanotime()
local r = MySQL.prepare.await('SELECT identifier from users WHERE lastname = ?', {'Linden'}) return result
queryTimesLocal[#queryTimesLocal+1] = (os.nanotime() - time) / 1000000
if i==1 then result = r end
end end
local queryMsLow, queryMsSum = 1000, 0 local initTable = {
[[CREATE TABLE IF NOT EXISTS `test_table` (
for _, v in pairs(queryTimesLocal) do queryMsSum = queryMsSum + v end `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
for _, v in pairs(queryTimesLocal) do `username` VARCHAR(50) NOT NULL DEFAULT '0',
if v < queryMsLow then queryMsLow = v end `identifier` VARCHAR(50) NOT NULL DEFAULT '0',
end PRIMARY KEY (`id`)
);]],
local averageQueryTime = queryMsSum / #queryTimesLocal 'TRUNCATE `test_table`',
print(json.encode(result)) 'ALTER TABLE `test_table` AUTO_INCREMENT = 1'
print('Low: '.. queryMsLow ..'ms | Avg: '..averageQueryTime..'ms | Total: '..queryMsSum..'ms ('..#queryTimesLocal..' queries)')
end)
```
## JavaScript
```js
const val = 10000;
RegisterCommand('jssync', async () => {
const queryTimesLocal = [];
let result;
await exports.oxmysql.prepare_async('SELECT identifier from users WHERE lastname = ?', ['Linden']);
for (let i = 0; i < val; i++) {
const startTime = process.hrtime();
const r = await exports.oxmysql.prepare_async('SELECT identifier from users WHERE lastname = ?', ['Linden']);
queryTimesLocal.push(process.hrtime(startTime)[1] / 1000000);
if (i === 0) result = r;
} }
const queryMsSum = queryTimesLocal.reduce((a, b) => a + b, 0); print('initialise test_table')
const queryMsLow = queryTimesLocal.sort((a, b) => a - b)[0]; execQuery(MySQL.transaction.await, initTable)
const averageQueryTime = queryMsSum / queryTimesLocal.length;
console.log(result); local insertUsers = {}
console.log(
'Low: ' + for i = 1, 10000 do
queryMsLow + insertUsers[i] = { 'INSERT INTO `test_table` (username, identifier) VALUES (?, ?)', { 'Testuser_'..i, 'abcdef'..i }}
'ms | Avg: ' + end
averageQueryTime +
'ms | Total: ' + print('insert test users')
queryMsSum + execQuery(MySQL.transaction.await, insertUsers)
'ms (' +
queryTimesLocal.length + local selectUserIds = {}
' queries)'
); for i = 1, 10000 do
}); if i % 4 == 0 then
selectUserIds[math.tointeger(i/4)] = { 'abcdef'..i }
end
end
print('select every 4th userid')
execQuery(MySQL.prepare.await, selectUserIds, 'SELECT `id` FROM `test_table` WHERE `identifier` = ? LIMIT 1')
end)
``` ```