©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The BENCHMARK SQL Function in MySQL and MariaDB - Measure speed of expressions

BENCHMARKSyntax:BENCHMARK(Number, Expression)
Return value:INTEGER
Function type:Information function
Function Description

The BENCHMARK() function executes the "Expression" repeatedly "Number" times.

It can be used to measure how fast the database is processing the expression.

The function is not suitable for measuring how fast queries from tables are because the query optimizer falsifies the result.

The result value is 0. If count is negative, the BENCHMARK() function returns NULL.

The function should be used with caution, as executing time- or resource-intensive expressions can adversely affect the overall performance of the server.

Examples of the BENCHMARK() function with MariaDB 10.3

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19

set @time=sysdate();
SELECT benchmark(100000000, adddate(now(), interval 1 second));
select timediff(sysdate(),@time);

set @time=sysdate();
SELECT benchmark(100000000, (select adddate(now(), interval 1 secondas n from menu limit 1));
select timediff(sysdate(),@time);

set @time=sysdate();
SELECT benchmark(100000000, (select count(*) from menu));
select timediff(sysdate(),@time);

set @time=sysdate();
SELECT benchmark(100000000, (select sum(pos) from menu));
select timediff(sysdate(),@time);

SELECT benchmark(-10000, (select sum(pos) from menu));

benchmark(100000000, adddate(now(), interval 1 second))
int(1)
0
timediff(sysdate(),@time)
time(10)
00:00:06
benchmark(100000000, (select adddate(now(), interval 1 second) as n from menu limit 1))
int(1)
0
timediff(sysdate(),@time)
time(10)
00:00:03
benchmark(100000000, (select count(*) from menu))
int(1)
0
timediff(sysdate(),@time)
time(10)
00:00:01
benchmark(100000000, (select sum(pos) from menu))
int(1)
0
timediff(sysdate(),@time)
time(10)
00:00:00
benchmark(-10000, (select sum(pos) from menu))
int(1)
NULL

Examples of then BENCHMARK() Function with MySQL 8.0

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19

set @time=sysdate();
SELECT benchmark(100000000, adddate(now(), interval 1 second));
select timediff(sysdate(),@time);

set @time=sysdate();
SELECT benchmark(100000000, (select adddate(now(), interval 1 secondas n from menu limit 1));
select timediff(sysdate(),@time);

set @time=sysdate();
SELECT benchmark(100000000, (select count(*) from menu));
select timediff(sysdate(),@time);

set @time=sysdate();
SELECT benchmark(100000000, (select sum(pos) from menu));
select timediff(sysdate(),@time);

SELECT benchmark(-10000, (select sum(pos) from menu));

benchmark(100000000, adddate(now(), interval 1 second))
bigint(1)
0
timediff(sysdate(),@time)
time(17)
00:00:21.000000
benchmark(100000000, (select adddate(now(), interval 1 second) as n from menu limit 1))
bigint(1)
0
timediff(sysdate(),@time)
time(17)
00:00:01.000000
benchmark(100000000, (select count(*) from menu))
bigint(1)
0
timediff(sysdate(),@time)
time(17)
00:00:02.000000
benchmark(100000000, (select sum(pos) from menu))
bigint(1)
0
timediff(sysdate(),@time)
time(17)
00:00:02.000000
benchmark(-10000, (select sum(pos) from menu))
bigint(1)
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the BENCHMARK() function in MySQL and MariaDB databases

In MySQL and MariaDB the BENCHMARK() function is used to evaluate a specific expression or function to run repeatedly for a specified number of iterations. The function is mainly used for benchmarking and performance testing purposes, where the execution time of a given expression or function can be evaluated to compare different approaches or measure performance improvements. The expression to be measured can be any valid SQL expression or any valid SQL function.

The BENCHMARK() function returns the result of the last iteration of the expression or function, however the actual result may not be meaningful even in benchmarking scenarios since its main purpose is to measure execution time. Using the function can impact server performance when performing complex or resource-intensive operations for a large number of iterations.
ATANATAN2AVGBENCHMARKBINBIN_TO_UUIDBIT_AND

Further MySQL und MariaDB SQL Information functions

BINLOG_GTID_POSBINLOG_GTID_POS()

CHARSETCHARSET(String)
More about CHARSET Function

COERCIBILITYCOERCIBILITY(String)
More about COERCIBILITY Function

COLLATIONCOLLATION(String)
More about COLLATION Function

CONNECTION_IDCONNECTION_ID()
More about CONNECTION_ID Function

CURRENT_USERCURRENT_USER()
More about CURRENT_USER Function

CURRENT_ROLECURRENT_ROLE()
More about CURRENT_ROLE Function

DATABASEDATABASE()
More about DATABASE Function

DECODE_HISTOGRAMDECODE_HISTOGRAM()

DEFAULTDEFAULT(Column)
More about DEFAULT Function

FOUND_ROWSFOUND_ROWS()
More about FOUND_ROWS Function

LAST_INSERT_IDLAST_INSERT_ID([Expression])
More about LAST_INSERT_ID Function

LAST_VALUELAST_VALUE(Expression [, Expression ...])
More about LAST_VALUE Function

ROWNUMROWNUM()

ROW_COUNTROW_COUNT()
More about ROW_COUNT Function

SCHEMASCHEMA()
More about SCHEMA Function

SESSION_USERSESSION_USER()
More about SESSION_USER Function

SYSTEM_USERSYSTEM_USER()
More about SYSTEM_USER Function

USERUSER()
More about USER Function

VERSIONVERSION()
More about VERSION Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the BENCHMARK SQL function: mysql.com and mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer