mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-01 14:38:50 +00:00
70 lines
2.1 KiB
Plaintext
70 lines
2.1 KiB
Plaintext
# Benchmark
|
|
|
|
Benchmarking is based on the time spent when to receive a response from exports.
|
|
Real query speeds will be reported in the debug UI and in the server console.
|
|
|
|
**Direct query**
|
|
- `SELECT username FROM test_table WHERE id = 68 LIMIT 1`
|
|
- Takes ~0.184ms
|
|
|
|
**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
|
|
CreateThread(function()
|
|
local function execQuery(fn, tbl, query)
|
|
local start = os.nanotime()
|
|
local result = fn(query or tbl, tbl)
|
|
local finish = os.nanotime()
|
|
|
|
print('Executed ' .. #tbl .. ' queries in ' .. (finish - start) / 1e6 .. 'ms')
|
|
|
|
return result
|
|
end
|
|
|
|
local initTable = {
|
|
[[CREATE TABLE IF NOT EXISTS `test_table` (
|
|
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`username` VARCHAR(50) NOT NULL DEFAULT '0',
|
|
`identifier` VARCHAR(50) NOT NULL DEFAULT '0',
|
|
PRIMARY KEY (`id`)
|
|
);]],
|
|
'TRUNCATE `test_table`',
|
|
'ALTER TABLE `test_table` AUTO_INCREMENT = 1'
|
|
}
|
|
|
|
print('initialise test_table')
|
|
execQuery(MySQL.transaction.await, initTable)
|
|
|
|
local insertUsers = {}
|
|
|
|
for i = 1, 10000 do
|
|
insertUsers[i] = { 'INSERT INTO `test_table` (username, identifier) VALUES (?, ?)', { 'Testuser_'..i, 'abcdef'..i }}
|
|
end
|
|
|
|
print('insert test users')
|
|
execQuery(MySQL.transaction.await, insertUsers)
|
|
|
|
local selectUserIds = {}
|
|
|
|
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)
|
|
```
|